From 035171290c8f0fc2f1456d1e6a8a95eb2876d9ad Mon Sep 17 00:00:00 2001 From: kron Date: Thu, 6 Nov 2025 11:29:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DBUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/audioManager.js | 20 +++++++++++++++++--- src/pages/audio-test.vue | 7 ++++++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/audioManager.js b/src/audioManager.js index d4a9555..5b27186 100644 --- a/src/audioManager.js +++ b/src/audioManager.js @@ -240,16 +240,30 @@ class AudioManager { // 播放指定音频 play(key) { - // 如果有正在播放的音频,先停止 - if (this.currentPlayingKey) { + // 覆盖播放:若当前播放且不是同一音频,先停止当前播放 + if (this.currentPlayingKey && this.currentPlayingKey !== key) { this.stop(this.currentPlayingKey); } const audio = this.audioMap.get(key); if (audio) { + // 同一音频:避免 stop() 触发 onStop 清除授权,使用 pause()+seek(0) + try { + audio.pause(); + } catch (_) {} + try { + if (typeof audio.seek === "function") { + audio.seek(0); + } else { + audio.startTime = 0; + } + } catch (_) { + audio.startTime = 0; + } + // 显式授权播放并立即播放 this.allowPlayMap.set(key, true); - console.log(`开始播放音频 ${key}`); + audio.play(); this.currentPlayingKey = key; } else { diff --git a/src/pages/audio-test.vue b/src/pages/audio-test.vue index 238707e..a81381f 100644 --- a/src/pages/audio-test.vue +++ b/src/pages/audio-test.vue @@ -24,7 +24,7 @@ onBeforeUnmount(() => {