From c11a108f5d79beb1eefdffeb7895d04add5f7a88 Mon Sep 17 00:00:00 2001 From: kron Date: Fri, 14 Nov 2025 09:25:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=92=AD=E6=94=BE=E7=9B=B8?= =?UTF-8?q?=E5=90=8C=E5=A3=B0=E9=9F=B3=E7=9A=84=E9=98=B2=E6=8A=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/audioManager.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/audioManager.js b/src/audioManager.js index 22483c1..ca0b17f 100644 --- a/src/audioManager.js +++ b/src/audioManager.js @@ -111,6 +111,10 @@ class AudioManager { this.sequenceIndex = 0; this.isSequenceRunning = false; + // 防重复播放保护 + this.lastPlayKey = null; + this.lastPlayAt = 0; + // 静音开关 this.isMuted = false; @@ -355,6 +359,13 @@ class AudioManager { // 内部方法:播放单个 key _playSingle(key, forceStopAll = false) { + // 200ms 内的同 key 重复播放直接忽略,避免“比比赛开始”这类重复首音 + const now = Date.now(); + if (this.lastPlayKey === key && now - this.lastPlayAt < 250) { + debugLog(`忽略快速重复播放: ${key}`); + return; + } + if (!this.networkOnline) { const audio = this.audioMap.get(key); const isReady = this.readyMap && this.readyMap.get(key); @@ -370,6 +381,9 @@ class AudioManager { this.stopAll(); } else if (this.currentPlayingKey && this.currentPlayingKey !== key) { this.stop(this.currentPlayingKey); + } else if (this.currentPlayingKey === key) { + // 同一音频正在播放:不重启,避免听到重复开头 + return; } const audio = this.audioMap.get(key); @@ -401,6 +415,8 @@ class AudioManager { audio.play(); this.currentPlayingKey = key; + this.lastPlayKey = key; + this.lastPlayAt = Date.now(); } else { debugLog(`音频 ${key} 不存在,尝试重新加载...`); this.reloadAudio(key);