Skip to content

Commit

Permalink
Revert "loop check with setTimeout"
Browse files Browse the repository at this point in the history
This reverts commit 718ce9c.
  • Loading branch information
kamakiri01 committed Dec 11, 2023
1 parent 718ce9c commit 2b4915a
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions src/plugin/HTMLAudioPlugin/HTMLAudioPlayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,15 @@ export class HTMLAudioPlayer extends AudioPlayer {
});
}
if (end != null) {
const onEnded: () => void = () => {
if (asset.loop) {
audio.currentTime = loopStart;
} else {
audio.pause();
}
};
const setTimer = function(): void {
setTimeout(() => {
onEnded();
setTimer();
}, (end - loopStart) * 1000);
};
// timeupdate イベント通知の精度が低いため、 setTimeout と併用する
// addEventListener は裏タブ時にも動作させるため残す
audio.addEventListener("timeupdate", () => {
if (end <= audio.currentTime) {
onEnded();
if (asset.loop) {
audio.currentTime = loopStart;
} else {
audio.pause();
}
}
});
setTimer();
}
}

Expand Down

0 comments on commit 2b4915a

Please sign in to comment.