From 7fd4411643ae560b703dfec9ec1c2874948a04f7 Mon Sep 17 00:00:00 2001 From: Djeeberjr Date: Sun, 1 Aug 2021 13:30:23 +0200 Subject: [PATCH] improved audio opener --- src/components/AudioOpener.tsx | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/src/components/AudioOpener.tsx b/src/components/AudioOpener.tsx index d6fc436..3557d3a 100644 --- a/src/components/AudioOpener.tsx +++ b/src/components/AudioOpener.tsx @@ -5,35 +5,23 @@ import { FileOpenerProps } from "../types/FileOpenerProps" const AudioOpener: React.FC = (props) => { - let audio: HTMLAudioElement + const audio = React.createRef() useEffect(()=>{ - if (audio){ - audio.pause() - audio.remove() + if(audio.current){ + audio.current.volume = 0.1 } - - audio = new Audio(genDownloadLink(props.file.id)) - audio.volume = 0.1 - },[props.file]) + },[audio]) useEffect(()=>{ - if(!props.active){ - audio.pause - console.debug("Pause") + if (!props.active && audio.current){ + audio.current.pause() } - console.debug("active",props.active) },[props.active]) return (
- +
) }