From dadaa831ba02762d7ea1629e3bbd5ceeee34b107 Mon Sep 17 00:00:00 2001 From: Tiago Ribeiro Date: Mon, 11 Sep 2023 09:06:01 +0100 Subject: [PATCH] Improved the duration display on Listening --- src/components/Low/AudioPlayer.tsx | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/components/Low/AudioPlayer.tsx b/src/components/Low/AudioPlayer.tsx index c2e3183d..f5286b66 100644 --- a/src/components/Low/AudioPlayer.tsx +++ b/src/components/Low/AudioPlayer.tsx @@ -21,11 +21,22 @@ export default function AudioPlayer({src, color, autoPlay = false, disabled = fa const audioPlayerRef = useRef(null); useEffect(() => { - if (audioPlayerRef && audioPlayerRef.current) { - const seconds = Math.floor(audioPlayerRef.current.duration); - setDuration(seconds); - } - }, [audioPlayerRef?.current?.readyState]); + const durationInterval = setInterval(() => { + console.log("WOOP", duration); + if (duration > 0) clearInterval(durationInterval); + + console.log("YEEHAW"); + + const seconds = Math.floor(audioPlayerRef?.current?.duration || 0); + if (seconds > 0) setDuration(seconds); + }, 300); + + if (duration > 0) clearInterval(durationInterval); + + return () => { + clearInterval(durationInterval); + }; + }, [duration]); useEffect(() => { let playingInterval: NodeJS.Timer | undefined = undefined;