添加兼容性处理
This commit is contained in:
@@ -162,10 +162,12 @@ class AudioManager {
|
|||||||
|
|
||||||
// 监听加载状态
|
// 监听加载状态
|
||||||
audio.onCanplay(() => {
|
audio.onCanplay(() => {
|
||||||
// 保险:预加载阶段确保不播放
|
// 预加载阶段:仅在未授权情况下暂停,避免用户刚点击播放被打断
|
||||||
try {
|
if (!this.allowPlayMap.get(key)) {
|
||||||
audio.pause();
|
try {
|
||||||
} catch (_) {}
|
audio.pause();
|
||||||
|
} catch (_) {}
|
||||||
|
}
|
||||||
clearTimeout(loadTimeout);
|
clearTimeout(loadTimeout);
|
||||||
debugLog(`音频 ${key} 已加载完成`);
|
debugLog(`音频 ${key} 已加载完成`);
|
||||||
uni.$emit("audioLoaded", 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) {
|
reloadAudio(key) {
|
||||||
if (audioFils[key]) {
|
if (audioFils[key]) {
|
||||||
|
|||||||
Reference in New Issue
Block a user