|
@ -174,6 +174,28 @@ const playAudioSequence = (audioUrls) => { |
|
|
currentUrl?.length |
|
|
currentUrl?.length |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
// 增强URL验证 |
|
|
|
|
|
if (!currentUrl || typeof currentUrl !== 'string' || currentUrl.trim() === '') { |
|
|
|
|
|
console.error(`音频 ${currentIndex + 1} URL无效,跳过该音频`); |
|
|
|
|
|
currentIndex++; |
|
|
|
|
|
setTimeout(() => { |
|
|
|
|
|
playNext(); |
|
|
|
|
|
}, 100); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 检查URL格式 |
|
|
|
|
|
try { |
|
|
|
|
|
new URL(currentUrl); |
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
console.error(`音频 ${currentIndex + 1} URL格式错误:`, currentUrl); |
|
|
|
|
|
currentIndex++; |
|
|
|
|
|
setTimeout(() => { |
|
|
|
|
|
playNext(); |
|
|
|
|
|
}, 100); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 设置当前音频URL |
|
|
// 设置当前音频URL |
|
|
audioStore.setCurrentAudioUrl(currentUrl); |
|
|
audioStore.setCurrentAudioUrl(currentUrl); |
|
|
|
|
|
|
|
@ -191,6 +213,11 @@ const playAudioSequence = (audioUrls) => { |
|
|
audioStore.isPlaying = true; |
|
|
audioStore.isPlaying = true; |
|
|
audioStore.isPaused = false; |
|
|
audioStore.isPaused = false; |
|
|
console.log(`开始播放音频 ${currentIndex + 1}`); |
|
|
console.log(`开始播放音频 ${currentIndex + 1}`); |
|
|
|
|
|
console.log('音频播放状态:', { |
|
|
|
|
|
duration: sound.duration(), |
|
|
|
|
|
state: sound.state(), |
|
|
|
|
|
playing: sound.playing() |
|
|
|
|
|
}); |
|
|
}, |
|
|
}, |
|
|
onpause: () => { |
|
|
onpause: () => { |
|
|
audioStore.isPlaying = false; |
|
|
audioStore.isPlaying = false; |
|
@ -204,6 +231,13 @@ const playAudioSequence = (audioUrls) => { |
|
|
audioStore.playbackPosition = 0; |
|
|
audioStore.playbackPosition = 0; |
|
|
console.log(`音频 ${currentIndex + 1} 播放完成`); |
|
|
console.log(`音频 ${currentIndex + 1} 播放完成`); |
|
|
currentIndex++; |
|
|
currentIndex++; |
|
|
|
|
|
// 如果是最后一个音频播放完成,立即清除实例 |
|
|
|
|
|
if (currentIndex >= audioSequence.length) { |
|
|
|
|
|
console.log('最后一个音频播放完成,清除音频实例'); |
|
|
|
|
|
audioStore.soundInstance = null; |
|
|
|
|
|
audioStore.nowSound = null; |
|
|
|
|
|
currentIndex = 0; // 立即重置索引 |
|
|
|
|
|
} |
|
|
// 播放下一个音频 |
|
|
// 播放下一个音频 |
|
|
setTimeout(() => { |
|
|
setTimeout(() => { |
|
|
playNext(); |
|
|
playNext(); |
|
@ -217,16 +251,50 @@ const playAudioSequence = (audioUrls) => { |
|
|
}, |
|
|
}, |
|
|
onloaderror: (id, err) => { |
|
|
onloaderror: (id, err) => { |
|
|
console.error(`音频 ${currentIndex + 1} 加载失败:`, err); |
|
|
console.error(`音频 ${currentIndex + 1} 加载失败:`, err); |
|
|
|
|
|
console.error('失败的音频URL:', currentUrl); |
|
|
|
|
|
console.error('错误详情:', { id, err }); |
|
|
|
|
|
|
|
|
|
|
|
// 增加重试机制 |
|
|
|
|
|
if (!sound.retryCount) { |
|
|
|
|
|
sound.retryCount = 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (sound.retryCount < 2) { |
|
|
|
|
|
sound.retryCount++; |
|
|
|
|
|
console.log(`音频 ${currentIndex + 1} 第${sound.retryCount}次重试加载`); |
|
|
|
|
|
setTimeout(() => { |
|
|
|
|
|
sound.load(); |
|
|
|
|
|
}, 1000 * sound.retryCount); // 递增延时重试 |
|
|
|
|
|
} else { |
|
|
|
|
|
console.warn(`音频 ${currentIndex + 1} 重试失败,跳过该音频`); |
|
|
currentIndex++; |
|
|
currentIndex++; |
|
|
// 跳过失败的音频,播放下一个 |
|
|
// 跳过失败的音频,播放下一个 |
|
|
setTimeout(() => { |
|
|
setTimeout(() => { |
|
|
playNext(); |
|
|
playNext(); |
|
|
}, 100); |
|
|
}, 100); |
|
|
|
|
|
} |
|
|
}, |
|
|
}, |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
audioStore.nowSound = sound; |
|
|
audioStore.nowSound = sound; |
|
|
audioStore.setAudioInstance(sound); |
|
|
audioStore.setAudioInstance(sound); |
|
|
|
|
|
|
|
|
|
|
|
// 添加播放超时检测 |
|
|
|
|
|
const playTimeout = setTimeout(() => { |
|
|
|
|
|
if (!audioStore.isPlaying && sound.state() === 'loading') { |
|
|
|
|
|
console.warn(`音频 ${currentIndex + 1} 播放超时,可能网络问题`); |
|
|
|
|
|
sound.stop(); |
|
|
|
|
|
currentIndex++; |
|
|
|
|
|
playNext(); |
|
|
|
|
|
} |
|
|
|
|
|
}, 10000); // 10秒超时 |
|
|
|
|
|
|
|
|
|
|
|
// 播放成功后清除超时 |
|
|
|
|
|
sound.once('play', () => { |
|
|
|
|
|
clearTimeout(playTimeout); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
console.log(`尝试播放音频 ${currentIndex + 1},URL: ${currentUrl}`); |
|
|
sound.play(); |
|
|
sound.play(); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
@ -647,17 +715,43 @@ watch( |
|
|
const isPlayingAudio = ref(false); |
|
|
const isPlayingAudio = ref(false); |
|
|
|
|
|
|
|
|
// 播放音频队列 |
|
|
// 播放音频队列 |
|
|
|
|
|
// 防止重复调用的标志 |
|
|
|
|
|
let isCallingPlayNext = false; |
|
|
|
|
|
// 当前播放索引 |
|
|
|
|
|
let currentPlayIndex = 0; |
|
|
|
|
|
|
|
|
const playNextAudio = () => { |
|
|
const playNextAudio = () => { |
|
|
if (audioQueue.value.length === 0 || isPlayingAudio.value) { |
|
|
|
|
|
|
|
|
console.log('=== playNextAudio 被调用 ==='); |
|
|
|
|
|
console.log('当前队列状态:', { |
|
|
|
|
|
queueLength: audioQueue.value.length, |
|
|
|
|
|
queueItems: audioQueue.value.map(item => item.name), |
|
|
|
|
|
currentPlayIndex: currentPlayIndex, |
|
|
|
|
|
isPlayingAudio: isPlayingAudio.value, |
|
|
|
|
|
isCallingPlayNext: isCallingPlayNext, |
|
|
|
|
|
audioStoreIsPlaying: audioStore.isPlaying |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
if (audioQueue.value.length === 0 || isPlayingAudio.value || isCallingPlayNext) { |
|
|
|
|
|
console.log('❌ 播放条件不满足 - 队列长度:', audioQueue.value.length, '正在播放:', isPlayingAudio.value, '正在调用:', isCallingPlayNext); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 检查是否已播放完所有音频(仅在队列不为空时重置) |
|
|
|
|
|
if (currentPlayIndex >= audioQueue.value.length && audioQueue.value.length > 0) { |
|
|
|
|
|
console.log('🔄 所有音频播放完成,重置索引从第一个开始'); |
|
|
|
|
|
currentPlayIndex = 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
isCallingPlayNext = true; |
|
|
isPlayingAudio.value = true; |
|
|
isPlayingAudio.value = true; |
|
|
const audioInfo = audioQueue.value.shift(); |
|
|
|
|
|
|
|
|
const audioInfo = audioQueue.value[currentPlayIndex]; |
|
|
|
|
|
|
|
|
console.log(`开始播放${audioInfo.name}音频`); |
|
|
|
|
|
|
|
|
console.log(`✅ 开始播放${audioInfo.name}音频 (索引:${currentPlayIndex}),队列总长度:`, audioQueue.value.length); |
|
|
|
|
|
console.log('完整队列内容:', audioQueue.value.map((item, index) => `${index === currentPlayIndex ? '▶️' : '⏸️'} ${item.name}`)); |
|
|
|
|
|
|
|
|
if (audioStore.nowSound) { |
|
|
|
|
|
|
|
|
// 只有在确实需要停止时才停止之前的音频 |
|
|
|
|
|
if (audioStore.nowSound && (audioStore.nowSound.playing() || audioStore.nowSound.state() === 'loading')) { |
|
|
|
|
|
console.log('停止之前的音频实例'); |
|
|
audioStore.nowSound.stop(); |
|
|
audioStore.nowSound.stop(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -669,7 +763,10 @@ watch( |
|
|
onplay: () => { |
|
|
onplay: () => { |
|
|
audioStore.isPlaying = true; |
|
|
audioStore.isPlaying = true; |
|
|
audioStore.isPaused = false; |
|
|
audioStore.isPaused = false; |
|
|
console.log(`${audioInfo.name}音频开始播放`); |
|
|
|
|
|
|
|
|
isPlayingAudio.value = true; // 确保状态同步 |
|
|
|
|
|
isCallingPlayNext = false; // 重置调用标志 |
|
|
|
|
|
console.log(`${audioInfo.name}音频开始播放,时长:`, audio.duration()); |
|
|
|
|
|
console.log('音频播放状态确认 - isPlayingAudio:', isPlayingAudio.value, 'audioStore.isPlaying:', audioStore.isPlaying); |
|
|
}, |
|
|
}, |
|
|
onpause: () => { |
|
|
onpause: () => { |
|
|
audioStore.isPlaying = false; |
|
|
audioStore.isPlaying = false; |
|
@ -683,26 +780,42 @@ watch( |
|
|
console.log(`${audioInfo.name}音频继续播放`); |
|
|
console.log(`${audioInfo.name}音频继续播放`); |
|
|
}, |
|
|
}, |
|
|
onend: () => { |
|
|
onend: () => { |
|
|
|
|
|
console.log(`${audioInfo.name}音频播放完成,准备播放下一个`); |
|
|
|
|
|
console.log('播放完成时的状态 - 当前索引:', currentPlayIndex, '队列长度:', audioQueue.value.length, 'isPlayingAudio:', isPlayingAudio.value); |
|
|
audioStore.isPlaying = false; |
|
|
audioStore.isPlaying = false; |
|
|
audioStore.isPaused = false; |
|
|
audioStore.isPaused = false; |
|
|
audioStore.playbackPosition = 0; |
|
|
audioStore.playbackPosition = 0; |
|
|
isPlayingAudio.value = false; |
|
|
isPlayingAudio.value = false; |
|
|
console.log(`${audioInfo.name}音频播放完成`); |
|
|
|
|
|
// 播放下一个音频 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 移动到下一个音频索引 |
|
|
|
|
|
currentPlayIndex++; |
|
|
|
|
|
|
|
|
|
|
|
// 确保只有在音频真正播放完成时才播放下一个 |
|
|
|
|
|
if (currentPlayIndex < audioQueue.value.length) { |
|
|
|
|
|
console.log(`队列中还有音频,500ms后播放下一个 (索引:${currentPlayIndex}),当前队列:`, audioQueue.value.map((item, index) => `${index === currentPlayIndex ? '▶️' : '⏸️'} ${item.name}`)); |
|
|
setTimeout(() => { |
|
|
setTimeout(() => { |
|
|
|
|
|
isCallingPlayNext = false; // 在调用前重置标志 |
|
|
playNextAudio(); |
|
|
playNextAudio(); |
|
|
}, 100); |
|
|
|
|
|
|
|
|
}, 500); |
|
|
|
|
|
} else { |
|
|
|
|
|
console.log('🎉 所有音频播放完成,清除音频实例,队列保持完整,下次播放将从第一个开始'); |
|
|
|
|
|
// 清除音频实例,确保重新播放时不会使用旧实例 |
|
|
|
|
|
audioStore.nowSound = null; |
|
|
|
|
|
audioStore.soundInstance = null; |
|
|
|
|
|
isCallingPlayNext = false; // 重置调用标志 |
|
|
|
|
|
} |
|
|
}, |
|
|
}, |
|
|
onstop: () => { |
|
|
onstop: () => { |
|
|
|
|
|
console.log(`${audioInfo.name}音频被停止`); |
|
|
audioStore.isPlaying = false; |
|
|
audioStore.isPlaying = false; |
|
|
audioStore.isPaused = false; |
|
|
audioStore.isPaused = false; |
|
|
audioStore.playbackPosition = 0; |
|
|
audioStore.playbackPosition = 0; |
|
|
isPlayingAudio.value = false; |
|
|
|
|
|
console.log(`${audioInfo.name}音频已停止`); |
|
|
|
|
|
|
|
|
// 注意:不要在onstop中设置isPlayingAudio.value = false,因为这可能是正常的音频切换 |
|
|
}, |
|
|
}, |
|
|
onloaderror: (id, err) => { |
|
|
onloaderror: (id, err) => { |
|
|
console.error(`${audioInfo.name}音频播放失败:`, err); |
|
|
console.error(`${audioInfo.name}音频播放失败:`, err); |
|
|
isPlayingAudio.value = false; |
|
|
isPlayingAudio.value = false; |
|
|
|
|
|
isCallingPlayNext = false; // 重置调用标志 |
|
|
// 播放下一个音频 |
|
|
// 播放下一个音频 |
|
|
setTimeout(() => { |
|
|
setTimeout(() => { |
|
|
playNextAudio(); |
|
|
playNextAudio(); |
|
@ -714,19 +827,61 @@ watch( |
|
|
audioStore.setCurrentAudioUrl(audioInfo.url); |
|
|
audioStore.setCurrentAudioUrl(audioInfo.url); |
|
|
audioStore.nowSound = audio; |
|
|
audioStore.nowSound = audio; |
|
|
audioStore.setAudioInstance(audio); |
|
|
audioStore.setAudioInstance(audio); |
|
|
|
|
|
|
|
|
|
|
|
console.log(`尝试播放${audioInfo.name}音频`); |
|
|
audio.play(); |
|
|
audio.play(); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
// 添加音频到播放队列 |
|
|
|
|
|
|
|
|
// 音频队列顺序管理 |
|
|
|
|
|
const audioQueueOrder = { |
|
|
|
|
|
'API1-第一个': 1, |
|
|
|
|
|
'API2-第二个': 2, |
|
|
|
|
|
'API3-第三个': 3, |
|
|
|
|
|
'API4-第四个': 4 |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// 添加音频到播放队列(确保顺序) |
|
|
const addToAudioQueue = (url, name) => { |
|
|
const addToAudioQueue = (url, name) => { |
|
|
|
|
|
console.log(`=== 添加音频到队列 ===`); |
|
|
|
|
|
console.log('URL:', url); |
|
|
|
|
|
console.log('Name:', name); |
|
|
|
|
|
console.log('音频启用状态:', audioStore.isVoiceEnabled); |
|
|
|
|
|
|
|
|
if (url && audioStore.isVoiceEnabled) { |
|
|
if (url && audioStore.isVoiceEnabled) { |
|
|
audioQueue.value.push({ url, name }); |
|
|
|
|
|
console.log(`音频${name}已添加到播放队列`); |
|
|
|
|
|
// 如果当前没有播放音频,立即开始播放 |
|
|
|
|
|
if (!isPlayingAudio.value) { |
|
|
|
|
|
|
|
|
const audioItem = { url, name, order: audioQueueOrder[name] || 999 }; |
|
|
|
|
|
audioQueue.value.push(audioItem); |
|
|
|
|
|
|
|
|
|
|
|
// 按顺序排序队列 |
|
|
|
|
|
audioQueue.value.sort((a, b) => a.order - b.order); |
|
|
|
|
|
|
|
|
|
|
|
console.log(`音频${name}已添加到播放队列,顺序:${audioItem.order}`); |
|
|
|
|
|
console.log('当前队列顺序:', audioQueue.value.map(item => `${item.name}(${item.order})`)); |
|
|
|
|
|
console.log('当前播放状态详情:'); |
|
|
|
|
|
console.log(' - isPlayingAudio:', isPlayingAudio.value); |
|
|
|
|
|
console.log(' - audioStore.isPlaying:', audioStore.isPlaying); |
|
|
|
|
|
console.log(' - audioStore.nowSound:', audioStore.nowSound); |
|
|
|
|
|
console.log(' - isCallingPlayNext:', isCallingPlayNext); |
|
|
|
|
|
console.log(' - 队列长度:', audioQueue.value.length); |
|
|
|
|
|
|
|
|
|
|
|
// 只有在确实没有音频在播放且这是第一个音频时才开始播放 |
|
|
|
|
|
if (!isPlayingAudio.value && !audioStore.isPlaying && audioQueue.value.length === 1) { |
|
|
|
|
|
console.log('✅ 条件满足:没有音频在播放且这是第一个音频,立即开始播放'); |
|
|
playNextAudio(); |
|
|
playNextAudio(); |
|
|
|
|
|
} else { |
|
|
|
|
|
console.log('⏳ 等待条件:', { |
|
|
|
|
|
isPlayingAudio: isPlayingAudio.value, |
|
|
|
|
|
audioStoreIsPlaying: audioStore.isPlaying, |
|
|
|
|
|
queueLength: audioQueue.value.length, |
|
|
|
|
|
reason: audioQueue.value.length > 1 ? '队列中已有其他音频' : '有音频正在播放' |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
console.log('❌ 跳过添加音频:', { |
|
|
|
|
|
hasUrl: !!url, |
|
|
|
|
|
voiceEnabled: audioStore.isVoiceEnabled |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
console.log(`=== 添加音频完成 ===`); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
// 重写audioStore的togglePlayPause方法以支持队列播放控制 |
|
|
// 重写audioStore的togglePlayPause方法以支持队列播放控制 |
|
@ -735,8 +890,11 @@ watch( |
|
|
console.log('主页音频控制按钮被点击'); |
|
|
console.log('主页音频控制按钮被点击'); |
|
|
console.log('当前音频状态 - isPlaying:', audioStore.isPlaying, 'isPaused:', audioStore.isPaused); |
|
|
console.log('当前音频状态 - isPlaying:', audioStore.isPlaying, 'isPaused:', audioStore.isPaused); |
|
|
console.log('当前音频实例:', audioStore.soundInstance); |
|
|
console.log('当前音频实例:', audioStore.soundInstance); |
|
|
|
|
|
console.log('队列播放状态 - isPlayingAudio:', isPlayingAudio.value, '队列长度:', audioQueue.value.length); |
|
|
|
|
|
console.log('当前播放索引:', currentPlayIndex, '是否所有音频播放完成:', currentPlayIndex >= audioQueue.value.length); |
|
|
|
|
|
|
|
|
if (audioStore.soundInstance) { |
|
|
|
|
|
|
|
|
// 检查是否所有音频都播放完成,如果是则重新开始 |
|
|
|
|
|
if (audioStore.soundInstance && currentPlayIndex < audioQueue.value.length && isPlayingAudio.value) { |
|
|
if (audioStore.isPlaying) { |
|
|
if (audioStore.isPlaying) { |
|
|
// 暂停当前音频 |
|
|
// 暂停当前音频 |
|
|
console.log('暂停当前音频'); |
|
|
console.log('暂停当前音频'); |
|
@ -752,10 +910,83 @@ watch( |
|
|
audioStore.soundInstance.play(); |
|
|
audioStore.soundInstance.play(); |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
console.log('没有音频实例,尝试播放队列中的音频'); |
|
|
|
|
|
// 没有音频实例时,尝试播放队列中的音频 |
|
|
|
|
|
if (!isPlayingAudio.value && audioQueue.value.length > 0) { |
|
|
|
|
|
|
|
|
console.log('没有音频实例,检查是否需要重新播放队列'); |
|
|
|
|
|
console.log('重新播放条件检查:', { |
|
|
|
|
|
isPlayingAudio: isPlayingAudio.value, |
|
|
|
|
|
queueLength: audioQueue.value.length, |
|
|
|
|
|
currentPlayIndex: currentPlayIndex, |
|
|
|
|
|
condition1: audioQueue.value.length === 0, |
|
|
|
|
|
condition2: currentPlayIndex >= audioQueue.value.length, |
|
|
|
|
|
finalCondition: !isPlayingAudio.value && (audioQueue.value.length === 0 || currentPlayIndex >= audioQueue.value.length) |
|
|
|
|
|
}); |
|
|
|
|
|
// 没有音频实例时,检查是否所有音频都播放完成 |
|
|
|
|
|
if (!isPlayingAudio.value && (audioQueue.value.length === 0 || currentPlayIndex >= audioQueue.value.length)) { |
|
|
|
|
|
console.log('所有音频播放完成,重新构建队列从第一个开始播放'); |
|
|
|
|
|
// 重新构建音频队列,按顺序添加所有音频(不自动播放) |
|
|
|
|
|
const audioItems = []; |
|
|
|
|
|
if (audioPreloadStatus.one.url) { |
|
|
|
|
|
audioItems.push({ url: audioPreloadStatus.one.url, name: "API1-第一个", order: 1 }); |
|
|
|
|
|
} |
|
|
|
|
|
if (audioPreloadStatus.two.url) { |
|
|
|
|
|
audioItems.push({ url: audioPreloadStatus.two.url, name: "API2-第二个", order: 2 }); |
|
|
|
|
|
} |
|
|
|
|
|
if (audioPreloadStatus.three.url) { |
|
|
|
|
|
audioItems.push({ url: audioPreloadStatus.three.url, name: "API3-第三个", order: 3 }); |
|
|
|
|
|
} |
|
|
|
|
|
if (audioPreloadStatus.four.url) { |
|
|
|
|
|
audioItems.push({ url: audioPreloadStatus.four.url, name: "API4-第四个", order: 4 }); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 按顺序排序并添加到队列 |
|
|
|
|
|
audioItems.sort((a, b) => a.order - b.order); |
|
|
|
|
|
audioQueue.value = audioItems; |
|
|
|
|
|
|
|
|
|
|
|
console.log('队列重建完成,队列内容:', audioQueue.value.map(item => item.name)); |
|
|
|
|
|
console.log('开始从第一个音频播放'); |
|
|
|
|
|
|
|
|
|
|
|
// 重置播放状态并开始播放第一个音频 |
|
|
|
|
|
if (audioQueue.value.length > 0) { |
|
|
|
|
|
// 完全重置所有播放相关状态 |
|
|
|
|
|
isPlayingAudio.value = false; |
|
|
|
|
|
isCallingPlayNext = false; |
|
|
|
|
|
currentPlayIndex = 0; // 重置播放索引到第一个音频 |
|
|
|
|
|
audioStore.isPlaying = false; |
|
|
|
|
|
audioStore.isPaused = false; |
|
|
|
|
|
audioStore.playbackPosition = 0; |
|
|
|
|
|
audioStore.nowSound = null; |
|
|
|
|
|
audioStore.soundInstance = null; |
|
|
|
|
|
|
|
|
|
|
|
console.log('🔄 状态完全重置完成,准备从第一个音频开始播放'); |
|
|
|
|
|
|
|
|
|
|
|
console.log('✅ 完全重置播放状态,准备播放第一个音频'); |
|
|
|
|
|
console.log('重置后状态检查:', { |
|
|
|
|
|
isPlayingAudio: isPlayingAudio.value, |
|
|
|
|
|
isCallingPlayNext: isCallingPlayNext, |
|
|
|
|
|
currentPlayIndex: currentPlayIndex, |
|
|
|
|
|
audioStoreIsPlaying: audioStore.isPlaying, |
|
|
|
|
|
queueLength: audioQueue.value.length |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
|
|
|
console.log('🚀 延迟后开始播放第一个音频'); |
|
|
|
|
|
console.log('播放前最终状态检查:', { |
|
|
|
|
|
currentPlayIndex: currentPlayIndex, |
|
|
|
|
|
queueLength: audioQueue.value.length, |
|
|
|
|
|
queueItems: audioQueue.value.map((item, index) => `${index}: ${item.name}`), |
|
|
|
|
|
isPlayingAudio: isPlayingAudio.value, |
|
|
|
|
|
isCallingPlayNext: isCallingPlayNext, |
|
|
|
|
|
audioStoreIsPlaying: audioStore.isPlaying, |
|
|
|
|
|
audioStoreInstance: !!audioStore.soundInstance |
|
|
|
|
|
}); |
|
|
|
|
|
console.log('🎯 即将调用 playNextAudio,期望播放:', audioQueue.value[currentPlayIndex]?.name || '无音频'); |
|
|
playNextAudio(); |
|
|
playNextAudio(); |
|
|
|
|
|
}, 200); |
|
|
|
|
|
} |
|
|
|
|
|
} else if (!isPlayingAudio.value && audioQueue.value.length > 0) { |
|
|
|
|
|
console.log('队列中还有音频,继续播放'); |
|
|
|
|
|
playNextAudio(); |
|
|
|
|
|
} else { |
|
|
|
|
|
console.log('无法播放 - isPlayingAudio:', isPlayingAudio.value, '队列长度:', audioQueue.value.length); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
@ -767,6 +998,10 @@ watch( |
|
|
return Promise.resolve(); |
|
|
return Promise.resolve(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 立即设置URL,确保即使预加载失败也能使用 |
|
|
|
|
|
audioPreloadStatus[apiKey].url = url; |
|
|
|
|
|
console.log(`设置音频${apiKey}的URL:`, url); |
|
|
|
|
|
|
|
|
return new Promise((resolve) => { |
|
|
return new Promise((resolve) => { |
|
|
const audio = new Howl({ |
|
|
const audio = new Howl({ |
|
|
src: [url], |
|
|
src: [url], |
|
@ -777,12 +1012,12 @@ watch( |
|
|
onload: () => { |
|
|
onload: () => { |
|
|
console.log(`音频${apiKey}预加载完成:`, url); |
|
|
console.log(`音频${apiKey}预加载完成:`, url); |
|
|
audioPreloadStatus[apiKey].loaded = true; |
|
|
audioPreloadStatus[apiKey].loaded = true; |
|
|
audioPreloadStatus[apiKey].url = url; |
|
|
|
|
|
resolve(); |
|
|
resolve(); |
|
|
}, |
|
|
}, |
|
|
onloaderror: (id, err) => { |
|
|
onloaderror: (id, err) => { |
|
|
console.error(`音频${apiKey}预加载失败:`, err); |
|
|
console.error(`音频${apiKey}预加载失败:`, err); |
|
|
audioPreloadStatus[apiKey].loaded = true; // 标记为已处理,避免阻塞 |
|
|
audioPreloadStatus[apiKey].loaded = true; // 标记为已处理,避免阻塞 |
|
|
|
|
|
// URL已经在上面设置了,即使预加载失败也保留URL |
|
|
resolve(); |
|
|
resolve(); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
@ -802,9 +1037,10 @@ watch( |
|
|
if (apiStatus.one.result) { |
|
|
if (apiStatus.one.result) { |
|
|
console.log("执行OneAPI代码(文本和音频同步开始):", apiStatus.one.result); |
|
|
console.log("执行OneAPI代码(文本和音频同步开始):", apiStatus.one.result); |
|
|
|
|
|
|
|
|
// 将第一个音频添加到播放队列 |
|
|
|
|
|
|
|
|
// 将第一个音频添加到播放队列(确保顺序:API1) |
|
|
if (audioPreloadStatus.one.url) { |
|
|
if (audioPreloadStatus.one.url) { |
|
|
addToAudioQueue(audioPreloadStatus.one.url, "第一个"); |
|
|
|
|
|
|
|
|
addToAudioQueue(audioPreloadStatus.one.url, "API1-第一个"); |
|
|
|
|
|
console.log("音频队列:添加API1音频,当前队列长度:", audioQueue.value.length); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 在这里添加OneAPI成功后需要执行的代码 |
|
|
// 在这里添加OneAPI成功后需要执行的代码 |
|
@ -817,7 +1053,7 @@ watch( |
|
|
class: "title1", |
|
|
class: "title1", |
|
|
type: "title1", |
|
|
type: "title1", |
|
|
content: codeData.value.name + "全景作战报告", |
|
|
content: codeData.value.name + "全景作战报告", |
|
|
date: moment().format("DD/MM/YYYY"), |
|
|
|
|
|
|
|
|
date: result21.data.date, |
|
|
}, |
|
|
}, |
|
|
"", |
|
|
"", |
|
|
50 |
|
|
50 |
|
@ -1047,9 +1283,10 @@ watch( |
|
|
if (apiStatus.two.result) { |
|
|
if (apiStatus.two.result) { |
|
|
console.log("执行TwoAPI代码:", apiStatus.two.result); |
|
|
console.log("执行TwoAPI代码:", apiStatus.two.result); |
|
|
|
|
|
|
|
|
// 将第二个音频添加到播放队列 |
|
|
|
|
|
|
|
|
// 将第二个音频添加到播放队列(确保顺序:API2) |
|
|
if (audioPreloadStatus.two.url) { |
|
|
if (audioPreloadStatus.two.url) { |
|
|
addToAudioQueue(audioPreloadStatus.two.url, "第二个"); |
|
|
|
|
|
|
|
|
addToAudioQueue(audioPreloadStatus.two.url, "API2-第二个"); |
|
|
|
|
|
console.log("音频队列:添加API2音频,当前队列长度:", audioQueue.value.length); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 在这里添加TwoAPI成功后需要执行的代码 |
|
|
// 在这里添加TwoAPI成功后需要执行的代码 |
|
@ -1125,9 +1362,10 @@ watch( |
|
|
if (apiStatus.three.result) { |
|
|
if (apiStatus.three.result) { |
|
|
console.log("执行ThreeAPI代码:", apiStatus.three.result); |
|
|
console.log("执行ThreeAPI代码:", apiStatus.three.result); |
|
|
|
|
|
|
|
|
// 将第三个音频添加到播放队列 |
|
|
|
|
|
|
|
|
// 将第三个音频添加到播放队列(确保顺序:API3) |
|
|
if (audioPreloadStatus.three.url) { |
|
|
if (audioPreloadStatus.three.url) { |
|
|
addToAudioQueue(audioPreloadStatus.three.url, "第三个"); |
|
|
|
|
|
|
|
|
addToAudioQueue(audioPreloadStatus.three.url, "API3-第三个"); |
|
|
|
|
|
console.log("音频队列:添加API3音频,当前队列长度:", audioQueue.value.length); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 在这里添加ThreeAPI成功后需要执行的代码 |
|
|
// 在这里添加ThreeAPI成功后需要执行的代码 |
|
@ -1186,7 +1424,7 @@ watch( |
|
|
|
|
|
|
|
|
// } |
|
|
// } |
|
|
// }, 50); // 调整速度为50ms/字符 |
|
|
// }, 50); // 调整速度为50ms/字符 |
|
|
addTypingTask(aiMessage3, [ac31, ac32], 180); |
|
|
|
|
|
|
|
|
addTypingTask(aiMessage3, [ac31, ac32], 200); |
|
|
|
|
|
|
|
|
// chatStore.messages.push({ |
|
|
// chatStore.messages.push({ |
|
|
// sender: "ai", |
|
|
// sender: "ai", |
|
@ -1267,7 +1505,7 @@ watch( |
|
|
addTypingTask( |
|
|
addTypingTask( |
|
|
aiMessage4, |
|
|
aiMessage4, |
|
|
[ac41, ac42, ac43, ac44, ac45, ac46, ac47, ac48], |
|
|
[ac41, ac42, ac43, ac44, ac45, ac46, ac47, ac48], |
|
|
180 |
|
|
|
|
|
|
|
|
200 |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
// chatStore.messages.push({ |
|
|
// chatStore.messages.push({ |
|
@ -1289,9 +1527,10 @@ watch( |
|
|
if (apiStatus.four.result) { |
|
|
if (apiStatus.four.result) { |
|
|
console.log("执行FourAPI代码:", apiStatus.four.result); |
|
|
console.log("执行FourAPI代码:", apiStatus.four.result); |
|
|
|
|
|
|
|
|
// 将第四个音频添加到播放队列 |
|
|
|
|
|
|
|
|
// 将第四个音频添加到播放队列(确保顺序:API4) |
|
|
if (audioPreloadStatus.four.url) { |
|
|
if (audioPreloadStatus.four.url) { |
|
|
addToAudioQueue(audioPreloadStatus.four.url, "第四个"); |
|
|
|
|
|
|
|
|
addToAudioQueue(audioPreloadStatus.four.url, "API4-第四个"); |
|
|
|
|
|
console.log("音频队列:添加API4音频,当前队列长度:", audioQueue.value.length); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 在这里添加FourAPI成功后需要执行的代码 |
|
|
// 在这里添加FourAPI成功后需要执行的代码 |
|
@ -1351,7 +1590,7 @@ watch( |
|
|
|
|
|
|
|
|
// } |
|
|
// } |
|
|
// }, 50); // 调整速度为50ms/字符 |
|
|
// }, 50); // 调整速度为50ms/字符 |
|
|
addTypingTask(aiMessage5, [ac51, ac52, ac53, ac54], 180); |
|
|
|
|
|
|
|
|
addTypingTask(aiMessage5, [ac51, ac52, ac53, ac54], 240); |
|
|
|
|
|
|
|
|
// chatStore.messages.push({ |
|
|
// chatStore.messages.push({ |
|
|
// sender: "ai", |
|
|
// sender: "ai", |
|
@ -1382,7 +1621,7 @@ watch( |
|
|
|
|
|
|
|
|
// } |
|
|
// } |
|
|
// }, 50); // 调整速度为50ms/字符 |
|
|
// }, 50); // 调整速度为50ms/字符 |
|
|
addTypingTask(aiMessage6, ["", ac6], 180); |
|
|
|
|
|
|
|
|
addTypingTask(aiMessage6, ["", ac6], 210); |
|
|
|
|
|
|
|
|
// chatStore.messages.push({ |
|
|
// chatStore.messages.push({ |
|
|
// sender: "ai", |
|
|
// sender: "ai", |
|
|