|
|
@ -717,18 +717,37 @@ watch( |
|
|
|
// 播放音频队列 |
|
|
|
// 防止重复调用的标志 |
|
|
|
let isCallingPlayNext = false; |
|
|
|
// 当前播放索引 |
|
|
|
let currentPlayIndex = 0; |
|
|
|
|
|
|
|
const playNextAudio = () => { |
|
|
|
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); |
|
|
|
console.log('❌ 播放条件不满足 - 队列长度:', audioQueue.value.length, '正在播放:', isPlayingAudio.value, '正在调用:', isCallingPlayNext); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// 检查是否已播放完所有音频(仅在队列不为空时重置) |
|
|
|
if (currentPlayIndex >= audioQueue.value.length && audioQueue.value.length > 0) { |
|
|
|
console.log('🔄 所有音频播放完成,重置索引从第一个开始'); |
|
|
|
currentPlayIndex = 0; |
|
|
|
} |
|
|
|
|
|
|
|
isCallingPlayNext = true; |
|
|
|
isPlayingAudio.value = true; |
|
|
|
const audioInfo = audioQueue.value.shift(); |
|
|
|
const audioInfo = audioQueue.value[currentPlayIndex]; |
|
|
|
|
|
|
|
console.log(`开始播放${audioInfo.name}音频,剩余队列:`, audioQueue.value.length); |
|
|
|
console.log(`✅ 开始播放${audioInfo.name}音频 (索引:${currentPlayIndex}),队列总长度:`, audioQueue.value.length); |
|
|
|
console.log('完整队列内容:', audioQueue.value.map((item, index) => `${index === currentPlayIndex ? '▶️' : '⏸️'} ${item.name}`)); |
|
|
|
|
|
|
|
// 只有在确实需要停止时才停止之前的音频 |
|
|
|
if (audioStore.nowSound && (audioStore.nowSound.playing() || audioStore.nowSound.state() === 'loading')) { |
|
|
@ -744,6 +763,7 @@ watch( |
|
|
|
onplay: () => { |
|
|
|
audioStore.isPlaying = true; |
|
|
|
audioStore.isPaused = false; |
|
|
|
isPlayingAudio.value = true; // 确保状态同步 |
|
|
|
isCallingPlayNext = false; // 重置调用标志 |
|
|
|
console.log(`${audioInfo.name}音频开始播放,时长:`, audio.duration()); |
|
|
|
console.log('音频播放状态确认 - isPlayingAudio:', isPlayingAudio.value, 'audioStore.isPlaying:', audioStore.isPlaying); |
|
|
@ -761,21 +781,27 @@ watch( |
|
|
|
}, |
|
|
|
onend: () => { |
|
|
|
console.log(`${audioInfo.name}音频播放完成,准备播放下一个`); |
|
|
|
console.log('播放完成时的状态 - 队列长度:', audioQueue.value.length, 'isPlayingAudio:', isPlayingAudio.value); |
|
|
|
console.log('播放完成时的状态 - 当前索引:', currentPlayIndex, '队列长度:', audioQueue.value.length, 'isPlayingAudio:', isPlayingAudio.value); |
|
|
|
audioStore.isPlaying = false; |
|
|
|
audioStore.isPaused = false; |
|
|
|
audioStore.playbackPosition = 0; |
|
|
|
isPlayingAudio.value = false; |
|
|
|
|
|
|
|
// 移动到下一个音频索引 |
|
|
|
currentPlayIndex++; |
|
|
|
|
|
|
|
// 确保只有在音频真正播放完成时才播放下一个 |
|
|
|
if (audioQueue.value.length > 0) { |
|
|
|
console.log('队列中还有音频,500ms后播放下一个,当前队列:', audioQueue.value.map(item => item.name)); |
|
|
|
if (currentPlayIndex < audioQueue.value.length) { |
|
|
|
console.log(`队列中还有音频,500ms后播放下一个 (索引:${currentPlayIndex}),当前队列:`, audioQueue.value.map((item, index) => `${index === currentPlayIndex ? '▶️' : '⏸️'} ${item.name}`)); |
|
|
|
setTimeout(() => { |
|
|
|
isCallingPlayNext = false; // 在调用前重置标志 |
|
|
|
playNextAudio(); |
|
|
|
}, 500); |
|
|
|
} else { |
|
|
|
console.log('所有音频播放完成'); |
|
|
|
console.log('🎉 所有音频播放完成,清除音频实例,队列保持完整,下次播放将从第一个开始'); |
|
|
|
// 清除音频实例,确保重新播放时不会使用旧实例 |
|
|
|
audioStore.nowSound = null; |
|
|
|
audioStore.soundInstance = null; |
|
|
|
isCallingPlayNext = false; // 重置调用标志 |
|
|
|
} |
|
|
|
}, |
|
|
@ -865,8 +891,10 @@ watch( |
|
|
|
console.log('当前音频状态 - isPlaying:', audioStore.isPlaying, 'isPaused:', audioStore.isPaused); |
|
|
|
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) { |
|
|
|
// 暂停当前音频 |
|
|
|
console.log('暂停当前音频'); |
|
|
@ -883,23 +911,77 @@ watch( |
|
|
|
} |
|
|
|
} else { |
|
|
|
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) { |
|
|
|
if (!isPlayingAudio.value && (audioQueue.value.length === 0 || currentPlayIndex >= audioQueue.value.length)) { |
|
|
|
console.log('所有音频播放完成,重新构建队列从第一个开始播放'); |
|
|
|
// 重新构建音频队列,按顺序添加所有音频 |
|
|
|
// 重新构建音频队列,按顺序添加所有音频(不自动播放) |
|
|
|
const audioItems = []; |
|
|
|
if (audioPreloadStatus.one.url) { |
|
|
|
addToAudioQueue(audioPreloadStatus.one.url, "API1-第一个"); |
|
|
|
audioItems.push({ url: audioPreloadStatus.one.url, name: "API1-第一个", order: 1 }); |
|
|
|
} |
|
|
|
if (audioPreloadStatus.two.url) { |
|
|
|
addToAudioQueue(audioPreloadStatus.two.url, "API2-第二个"); |
|
|
|
audioItems.push({ url: audioPreloadStatus.two.url, name: "API2-第二个", order: 2 }); |
|
|
|
} |
|
|
|
if (audioPreloadStatus.three.url) { |
|
|
|
addToAudioQueue(audioPreloadStatus.three.url, "API3-第三个"); |
|
|
|
audioItems.push({ url: audioPreloadStatus.three.url, name: "API3-第三个", order: 3 }); |
|
|
|
} |
|
|
|
if (audioPreloadStatus.four.url) { |
|
|
|
addToAudioQueue(audioPreloadStatus.four.url, "API4-第四个"); |
|
|
|
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(); |
|
|
|
}, 200); |
|
|
|
} |
|
|
|
console.log('队列重建完成,开始从第一个音频播放'); |
|
|
|
} else if (!isPlayingAudio.value && audioQueue.value.length > 0) { |
|
|
|
console.log('队列中还有音频,继续播放'); |
|
|
|
playNextAudio(); |
|
|
@ -1342,7 +1424,7 @@ watch( |
|
|
|
|
|
|
|
// } |
|
|
|
// }, 50); // 调整速度为50ms/字符 |
|
|
|
addTypingTask(aiMessage3, [ac31, ac32], 180); |
|
|
|
addTypingTask(aiMessage3, [ac31, ac32], 200); |
|
|
|
|
|
|
|
// chatStore.messages.push({ |
|
|
|
// sender: "ai", |
|
|
@ -1423,7 +1505,7 @@ watch( |
|
|
|
addTypingTask( |
|
|
|
aiMessage4, |
|
|
|
[ac41, ac42, ac43, ac44, ac45, ac46, ac47, ac48], |
|
|
|
180 |
|
|
|
200 |
|
|
|
); |
|
|
|
|
|
|
|
// chatStore.messages.push({ |
|
|
@ -1508,7 +1590,7 @@ watch( |
|
|
|
|
|
|
|
// } |
|
|
|
// }, 50); // 调整速度为50ms/字符 |
|
|
|
addTypingTask(aiMessage5, [ac51, ac52, ac53, ac54], 180); |
|
|
|
addTypingTask(aiMessage5, [ac51, ac52, ac53, ac54], 240); |
|
|
|
|
|
|
|
// chatStore.messages.push({ |
|
|
|
// sender: "ai", |
|
|
@ -1539,7 +1621,7 @@ watch( |
|
|
|
|
|
|
|
// } |
|
|
|
// }, 50); // 调整速度为50ms/字符 |
|
|
|
addTypingTask(aiMessage6, ["", ac6], 180); |
|
|
|
addTypingTask(aiMessage6, ["", ac6], 210); |
|
|
|
|
|
|
|
// chatStore.messages.push({ |
|
|
|
// sender: "ai", |
|
|
|