优化播放
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled

This commit is contained in:
Song367 2025-10-21 11:10:33 +08:00
parent 0c410b9f57
commit 8fb1e3c963

View File

@ -56,56 +56,43 @@ let isFirstChunk = true;
// 队列处理器 - 独立运行,按顺序播放音频
async function processAudioQueue() {
if (isProcessingQueue) return;
isProcessingQueue = true;
while (audioQueue.length > 0 && !isPlaying) {
console.log('开始处理音频队列');
// 如果当前没有音频在播放,且队列中有音频
if (!isPlaying && audioQueue.length > 0) {
const audioItem = audioQueue.shift();
const sayName = '8-4-sh'
const targetVideo = window.webrtcApp.interactionVideo
// 如果是第一个音频片段,触发视频切换
const sayName = '8-4-sh';
const targetVideo = window.webrtcApp.interactionVideo;
if (sayName != window.webrtcApp.currentVideoTag && window.webrtcApp && window.webrtcApp.switchVideoStream) {
try {
// 检查WebSocket连接状态
// 检查WebSocket连接状态(仅影响服务端广播,不阻断本地播放)
if (window.webrtcApp.checkConnectionStatus && !window.webrtcApp.checkConnectionStatus()) {
console.log('WebSocket连接异常跳过视频切换');
return;
}
console.log('WebSocket连接异常继续本地播放并切换视频');
} else {
console.log('--------------触发视频切换:', sayName);
window.webrtcApp.switchVideoStream(targetVideo, 'audio', '8-4-sh');
}
isFirstChunk = false;
window.webrtcApp.currentVideoTag = sayName;
} catch (error) {
console.error('视频切换失败:', error);
}
}
await playAudioData(audioItem.audioData);
} else {
// 等待一小段时间再检查
await new Promise(resolve => setTimeout(resolve, 50));
}
}
isProcessingQueue = false;
// 等待当前音频播放完成后再切换回默认视频
// while (isPlaying) {
// console.log("触发音频等待")
// await new Promise(resolve => setTimeout(resolve, 1000));
// }
// console.log("触发音频等待")
// await new Promise(resolve => setTimeout(resolve, 300));
const text = 'default'
console.log("音频结束------------------------", window.webrtcApp.currentVideoTag, isPlaying)
const text = 'default';
console.log("音频结束------------------------", window.webrtcApp.currentVideoTag, isPlaying);
if (window.webrtcApp.currentVideoTag != text && !isPlaying) {
isFirstChunk = true
window.webrtcApp.currentVideoTag = text
isFirstChunk = true;
window.webrtcApp.currentVideoTag = text;
window.webrtcApp.switchVideoStream(window.webrtcApp.defaultVideo, 'audio', text);
}
console.log('音频队列处理完成');