From a85ade2bb2af9b70d1810e9fb0d134f0ff57b156 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=8B=E6=9D=B0?= Date: Sat, 16 Aug 2025 14:35:42 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=83=85=E7=BB=AA=E5=A4=A7?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E9=9F=B3=E9=A2=91=E5=96=87=E5=8F=AD=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/AiEmotion.vue | 83 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 77 insertions(+), 6 deletions(-) diff --git a/src/views/AiEmotion.vue b/src/views/AiEmotion.vue index 08afd97..75277f2 100644 --- a/src/views/AiEmotion.vue +++ b/src/views/AiEmotion.vue @@ -1477,6 +1477,13 @@ const playNextAudio = () => { emotionAudioStore.isPlaying = true; console.log(`开始播放${audioInfo.name}音频`); + // 设置当前股票的音频播放状态为播放中 + const currentStock = emotionStore.activeStock; + if (currentStock) { + setStockAudioState(currentStock, { isPlaying: true, isPaused: false }); + console.log('设置当前股票音频状态为播放中:', currentStock.stockInfo?.name); + } + // 如果是第一个音频且需要启动打字机效果,则启动 if ( currentPlayIndex === 0 && @@ -1484,26 +1491,46 @@ const playNextAudio = () => { parsedConclusion.value ) { console.log("🎬 第一个音频开始播放,同时启动打字机效果"); - const currentStock = emotionStore.activeStock; const stockId = currentStock?.stockInfo?.code || currentStock?.stockInfo?.symbol; startTypewriterEffect(parsedConclusion.value, stockId, audioInfo.onComplete); } }, onpause: () => { + emotionAudioStore.isPlaying = false; emotionAudioStore.isPaused = true; - console.log(`${audioInfo.name}音频暂停播放`); + // 保存当前播放位置 + if (audio && audio.seek) { + emotionAudioStore.playbackPosition = audio.seek() || 0; + } + console.log(`${audioInfo.name}音频暂停播放,位置:`, emotionAudioStore.playbackPosition); + + // 设置当前股票的音频播放状态为暂停 + const currentStock = emotionStore.activeStock; + if (currentStock) { + setStockAudioState(currentStock, { isPlaying: false, isPaused: true }); + console.log('设置当前股票音频状态为暂停:', currentStock.stockInfo?.name); + } }, onresume: () => { + emotionAudioStore.isPlaying = true; emotionAudioStore.isPaused = false; - console.log(`${audioInfo.name}音频继续播放`); + // 如果有保存的播放位置,从该位置继续播放 + if (emotionAudioStore.playbackPosition > 0 && audio && audio.seek) { + audio.seek(emotionAudioStore.playbackPosition); + } + console.log(`${audioInfo.name}音频继续播放,位置:`, emotionAudioStore.playbackPosition); + + // 设置当前股票的音频播放状态为播放中 + const currentStock = emotionStore.activeStock; + if (currentStock) { + setStockAudioState(currentStock, { isPlaying: true, isPaused: false }); + console.log('设置当前股票音频状态为播放中:', currentStock.stockInfo?.name); + } }, onend: () => { console.log(`${audioInfo.name}音频播放完成,准备播放下一个`); - emotionAudioStore.isPlaying = false; emotionAudioStore.isPaused = false; emotionAudioStore.playbackPosition = 0; - isAudioPlaying.value = false; - isPlayingQueueAudio.value = false; // 移动到下一个音频索引 currentPlayIndex++; @@ -1513,14 +1540,30 @@ const playNextAudio = () => { console.log( `队列中还有音频,500ms后播放下一个 (索引:${currentPlayIndex})` ); + // 重置调用标志,但保持播放状态,直到所有音频播放完成 setTimeout(() => { isCallingPlayNext = false; + isPlayingQueueAudio.value = false; // 重置队列播放状态,允许播放下一个音频 + // 保持emotionAudioStore.isPlaying为true,确保喇叭图片保持voice状态 + emotionAudioStore.isPlaying = true; + // 设置下一个音频的URL,确保togglePlayPause能正确工作 + const nextAudioInfo = audioQueue.value[currentPlayIndex]; + if (nextAudioInfo && nextAudioInfo.url) { + emotionAudioStore.setCurrentAudioUrl(nextAudioInfo.url); + } playNextAudio(); }, 500); } else { console.log("🎉 所有音频播放完成"); emotionAudioStore.nowSound = null; isCallingPlayNext = false; + + // 重置音频store的播放状态 + emotionAudioStore.isPlaying = false; + emotionAudioStore.isPaused = false; + emotionAudioStore.playbackPosition = 0; + isAudioPlaying.value = false; + isPlayingQueueAudio.value = false; // 重置当前股票的音频播放状态(所有音频播放完成后按钮应该变暗) const currentStock = emotionStore.activeStock; @@ -1768,6 +1811,13 @@ function playAudio(url) { isAudioPlaying.value = true; emotionAudioStore.isPlaying = true; console.log("开始播放场景应用语音"); + + // 设置当前股票的音频播放状态为播放中 + const currentStock = emotionStore.activeStock; + if (currentStock) { + setStockAudioState(currentStock, { isPlaying: true, isPaused: false }); + console.log('设置当前股票音频状态为播放中:', currentStock.stockInfo?.name); + } // 音频开始播放时的自动滚动已移除 }, onend: () => { @@ -1776,16 +1826,37 @@ function playAudio(url) { emotionAudioStore.isPaused = false; emotionAudioStore.playbackPosition = 0; console.log("场景应用语音播放结束"); + + // 重置当前股票的音频播放状态 + const currentStock = emotionStore.activeStock; + if (currentStock) { + setStockAudioState(currentStock, { isPlaying: false, isPaused: false }); + console.log('重置当前股票音频状态:', currentStock.stockInfo?.name); + } }, onstop: () => { isAudioPlaying.value = false; emotionAudioStore.isPlaying = false; console.log("场景应用语音播放停止"); + + // 重置当前股票的音频播放状态 + const currentStock = emotionStore.activeStock; + if (currentStock) { + setStockAudioState(currentStock, { isPlaying: false, isPaused: false }); + console.log('重置当前股票音频状态:', currentStock.stockInfo?.name); + } }, onpause: () => { isAudioPlaying.value = false; emotionAudioStore.isPlaying = false; console.log("场景应用语音播放暂停"); + + // 设置当前股票的音频播放状态为暂停 + const currentStock = emotionStore.activeStock; + if (currentStock) { + setStockAudioState(currentStock, { isPlaying: false, isPaused: true }); + console.log('设置当前股票音频状态为暂停:', currentStock.stockInfo?.name); + } }, onerror: (error) => { isAudioPlaying.value = false;