From 0dc8c67cf5a7f6f408a82155a7e0c27df5f3e59b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=8B=E6=9D=B0?= Date: Thu, 3 Jul 2025 13:30:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=BA=E5=AE=9D=E5=A5=87=E5=85=B5=E8=AF=AD?= =?UTF-8?q?=E9=9F=B3=E9=98=9F=E5=88=97=E6=92=AD=E6=94=BE=E5=AE=8C=E6=88=90?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/AIchat.vue | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/views/AIchat.vue b/src/views/AIchat.vue index 3127864..f5a6bbf 100644 --- a/src/views/AIchat.vue +++ b/src/views/AIchat.vue @@ -657,9 +657,21 @@ watch( audioStore.isPaused = false; console.log(`${audioInfo.name}音频开始播放`); }, + onpause: () => { + audioStore.isPlaying = false; + audioStore.isPaused = true; + audioStore.playbackPosition = audio.seek() || 0; + console.log(`${audioInfo.name}音频已暂停,位置:`, audioStore.playbackPosition); + }, + onresume: () => { + audioStore.isPlaying = true; + audioStore.isPaused = false; + console.log(`${audioInfo.name}音频继续播放`); + }, onend: () => { audioStore.isPlaying = false; audioStore.isPaused = false; + audioStore.playbackPosition = 0; isPlayingAudio.value = false; console.log(`${audioInfo.name}音频播放完成`); // 播放下一个音频 @@ -667,6 +679,13 @@ watch( playNextAudio(); }, 100); }, + onstop: () => { + audioStore.isPlaying = false; + audioStore.isPaused = false; + audioStore.playbackPosition = 0; + isPlayingAudio.value = false; + console.log(`${audioInfo.name}音频已停止`); + }, onloaderror: (id, err) => { console.error(`${audioInfo.name}音频播放失败:`, err); isPlayingAudio.value = false; @@ -677,6 +696,8 @@ watch( } }); + // 设置当前音频URL到store + audioStore.setCurrentAudioUrl(audioInfo.url); audioStore.nowSound = audio; audioStore.setAudioInstance(audio); audio.play(); @@ -694,6 +715,37 @@ watch( } }; + // 重写audioStore的togglePlayPause方法以支持队列播放控制 + const originalTogglePlayPause = audioStore.togglePlayPause; + audioStore.togglePlayPause = () => { + console.log('主页音频控制按钮被点击'); + console.log('当前音频状态 - isPlaying:', audioStore.isPlaying, 'isPaused:', audioStore.isPaused); + console.log('当前音频实例:', audioStore.soundInstance); + + if (audioStore.soundInstance) { + if (audioStore.isPlaying) { + // 暂停当前音频 + console.log('暂停当前音频'); + audioStore.soundInstance.pause(); + } else if (audioStore.isPaused && audioStore.playbackPosition > 0) { + // 从暂停位置继续播放 + console.log('从暂停位置继续播放音频,位置:', audioStore.playbackPosition); + audioStore.soundInstance.seek(audioStore.playbackPosition); + audioStore.soundInstance.play(); + } else { + // 重新开始播放 + console.log('重新开始播放音频'); + audioStore.soundInstance.play(); + } + } else { + console.log('没有音频实例,尝试播放队列中的音频'); + // 没有音频实例时,尝试播放队列中的音频 + if (!isPlayingAudio.value && audioQueue.value.length > 0) { + playNextAudio(); + } + } + }; + // 预加载音频函数 const preloadAudio = (url, apiKey) => { if (!url || !audioStore.isVoiceEnabled) {