improved audio opener

This commit is contained in:
Djeeberjr 2021-08-01 13:30:23 +02:00
parent 5a31062b21
commit 7fd4411643

View File

@ -5,35 +5,23 @@ import { FileOpenerProps } from "../types/FileOpenerProps"
const AudioOpener: React.FC<FileOpenerProps> = (props) => {
let audio: HTMLAudioElement
const audio = React.createRef<HTMLAudioElement>()
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 (
<div>
<button onClick={()=>{
if (audio){
(audio.paused && audio.play()) || audio.pause()
}
}}>
Play/Pause
</button>
<audio src={genDownloadLink(props.file.id)} controls ref={audio}></audio>
</div>
)
}