添加播放相同声音的防抖
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user