fix: 更好的未交互不播放修复方案

This commit is contained in:
unanmed 2025-01-27 23:02:56 +08:00
parent 53fa7272fc
commit 19a0c29015

View File

@ -35,16 +35,6 @@ export class AudioPlayer extends EventEmitter<AudioPlayerEvent> {
this.ac = new AudioContext();
this.gain = this.ac.createGain();
this.gain.connect(this.ac.destination);
const func = () => {
this.ac.resume();
document.body.removeEventListener('mousedown', func);
document.body.removeEventListener('touchstart', func);
document.body.removeEventListener('keydown', func);
};
document.body.addEventListener('mousedown', func, { capture: true });
document.body.addEventListener('touchstart', func, { capture: true });
document.body.addEventListener('keydown', func, { capture: true });
}
/**
@ -427,9 +417,10 @@ export class AudioRoute
*
* @param when
*/
play(when: number = 0) {
async play(when: number = 0) {
if (this.status === AudioStatus.Playing) return;
this.link();
await this.player.ac.resume();
if (this.effectRoute.length > 0) {
const first = this.effectRoute[0];
this.source.connect(first);