添加兼容性处理

This commit is contained in:
kron
2025-11-06 14:06:37 +08:00
parent 035171290c
commit d637a0fa72

View File

@@ -162,10 +162,12 @@ class AudioManager {
// 监听加载状态
audio.onCanplay(() => {
// 保险:预加载阶段确保不播放
try {
audio.pause();
} catch (_) {}
// 预加载阶段:仅在未授权情况下暂停,避免用户刚点击播放被打断
if (!this.allowPlayMap.get(key)) {
try {
audio.pause();
} catch (_) {}
}
clearTimeout(loadTimeout);
debugLog(`音频 ${key} 已加载完成`);
uni.$emit("audioLoaded", key);
@@ -284,6 +286,34 @@ class AudioManager {
}
}
// 停止所有音频
stopAll() {
for (const [k, audio] of this.audioMap.entries()) {
try {
audio.stop();
} catch (_) {}
this.allowPlayMap.set(k, false);
}
this.currentPlayingKey = null;
}
// 销毁所有音频实例并清理状态
destroyAll() {
for (const [k, audio] of this.audioMap.entries()) {
try {
audio.destroy();
} catch (_) {}
this.allowPlayMap.delete(k);
this.retryCount.delete(k);
this.audioMap.delete(k);
}
this.audioKeys = [];
this.currentLoadingIndex = 0;
this.isLoading = false;
this.loadingPromise = null;
this.currentPlayingKey = null;
}
// 手动重新加载指定音频
reloadAudio(key) {
if (audioFils[key]) {