Improved the duration display on Listening
This commit is contained in:
@@ -21,11 +21,22 @@ export default function AudioPlayer({src, color, autoPlay = false, disabled = fa
|
|||||||
const audioPlayerRef = useRef<HTMLAudioElement | null>(null);
|
const audioPlayerRef = useRef<HTMLAudioElement | null>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (audioPlayerRef && audioPlayerRef.current) {
|
const durationInterval = setInterval(() => {
|
||||||
const seconds = Math.floor(audioPlayerRef.current.duration);
|
console.log("WOOP", duration);
|
||||||
setDuration(seconds);
|
if (duration > 0) clearInterval(durationInterval);
|
||||||
}
|
|
||||||
}, [audioPlayerRef?.current?.readyState]);
|
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(() => {
|
useEffect(() => {
|
||||||
let playingInterval: NodeJS.Timer | undefined = undefined;
|
let playingInterval: NodeJS.Timer | undefined = undefined;
|
||||||
|
|||||||
Reference in New Issue
Block a user