修复BUG

This commit is contained in:
kron
2025-11-06 11:29:08 +08:00
parent ae9ec4a7f7
commit 035171290c
2 changed files with 23 additions and 4 deletions

View File

@@ -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 {