improved audio opener
This commit is contained in:
parent
5a31062b21
commit
7fd4411643
@ -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>
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user