Skip to content

Commit

Permalink
Add stall recovery
Browse files Browse the repository at this point in the history
  • Loading branch information
0x1eef committed Oct 13, 2023
1 parent 5051284 commit 4615db4
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/js/components/AudioControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,16 @@ export function AudioControl({
const audio = useMemo(() => new Audio(), []);
const turnOnSound = () => setSoundOn(true);
const turnOffSound = () => setSoundOn(false);
const recover = () => {
if (!soundOn) return;
onStall();
audio.play()
.catch(() => setTimeout(recover, 1000));
};

useEffect(() => {
audio.addEventListener("ended", () => onEnd(turnOffSound));
audio.addEventListener("stalled", onStall);
audio.addEventListener("stalled", recover);
audio.addEventListener("waiting", onStall);
audio.addEventListener("play", onPlay);
audio.addEventListener("playing", onPlaying);
Expand Down

0 comments on commit 4615db4

Please sign in to comment.