修复BUG
This commit is contained in:
@@ -240,16 +240,30 @@ class AudioManager {
|
|||||||
|
|
||||||
// 播放指定音频
|
// 播放指定音频
|
||||||
play(key) {
|
play(key) {
|
||||||
// 如果有正在播放的音频,先停止
|
// 覆盖播放:若当前播放且不是同一音频,先停止当前播放
|
||||||
if (this.currentPlayingKey) {
|
if (this.currentPlayingKey && this.currentPlayingKey !== key) {
|
||||||
this.stop(this.currentPlayingKey);
|
this.stop(this.currentPlayingKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
const audio = this.audioMap.get(key);
|
const audio = this.audioMap.get(key);
|
||||||
if (audio) {
|
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);
|
this.allowPlayMap.set(key, true);
|
||||||
console.log(`开始播放音频 ${key}`);
|
|
||||||
audio.play();
|
audio.play();
|
||||||
this.currentPlayingKey = key;
|
this.currentPlayingKey = key;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ onBeforeUnmount(() => {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<Container title="应聘测试">
|
<Container title="音频测试">
|
||||||
<view class="container">
|
<view class="container">
|
||||||
<view v-for="key in Object.keys(audioFils)" :key="key">
|
<view v-for="key in Object.keys(audioFils)" :key="key">
|
||||||
<text>{{ key }}</text>
|
<text>{{ key }}</text>
|
||||||
@@ -47,5 +47,10 @@ onBeforeUnmount(() => {
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
padding: 25rpx;
|
padding: 25rpx;
|
||||||
|
color: #fff;
|
||||||
|
border-bottom: 1rpx solid #fff9;
|
||||||
|
}
|
||||||
|
.container > view > button {
|
||||||
|
color: #fff;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user