From 4615db46f0c6c1987cff2015f0c6118b1f2f791c Mon Sep 17 00:00:00 2001 From: 0x1eef <0x1eef@protonmail.com> Date: Fri, 13 Oct 2023 02:54:19 -0300 Subject: [PATCH] Add stall recovery --- src/js/components/AudioControl.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/js/components/AudioControl.tsx b/src/js/components/AudioControl.tsx index 9aab080bd..c81ce2626 100644 --- a/src/js/components/AudioControl.tsx +++ b/src/js/components/AudioControl.tsx @@ -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);