修复BUG
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -24,7 +24,7 @@ onBeforeUnmount(() => {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Container title="应聘测试">
|
||||
<Container title="音频测试">
|
||||
<view class="container">
|
||||
<view v-for="key in Object.keys(audioFils)" :key="key">
|
||||
<text>{{ key }}</text>
|
||||
@@ -47,5 +47,10 @@ onBeforeUnmount(() => {
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 25rpx;
|
||||
color: #fff;
|
||||
border-bottom: 1rpx solid #fff9;
|
||||
}
|
||||
.container > view > button {
|
||||
color: #fff;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user