Commit bdb547f0 authored by love_飞影's avatar love_飞影

refactor: 调整未启播逻辑

parent 37d1ec28
Pipeline #26470 passed with stages
in 7 minutes and 57 seconds
...@@ -32,13 +32,15 @@ export class NeosAudioContext extends EventEmitter<AudioScheduledSourceNodeEvent ...@@ -32,13 +32,15 @@ export class NeosAudioContext extends EventEmitter<AudioScheduledSourceNodeEvent
}; };
document.addEventListener("click", autoPlay); document.addEventListener("click", autoPlay);
} }
// 如果超过音频长度还未播放,说明播放失败了,重新播放 // 50ms 未启播,说明播放失败了,重新尝试播放
const timeout = setTimeout(async () => { const timeout = setTimeout(async () => {
if (source.loop) return; if (source.loop) return;
if (this.state === "closed") return; if (this.state === "closed") return;
await this.suspend(); if (source.context.currentTime === 0) {
await this.resume(); await this.suspend();
}, buffer.duration * 1000); await this.resume();
}
}, 50);
// 播放结束后关闭音频 // 播放结束后关闭音频
const Ended = () => { const Ended = () => {
source.removeEventListener("ended", Ended); source.removeEventListener("ended", Ended);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment