diff --git a/public/audios/audio.webm b/public/audios/audio.webm new file mode 100644 index 0000000..ba1a117 Binary files /dev/null and b/public/audios/audio.webm differ diff --git a/src/components/AudioPlayer.tsx b/src/components/AudioPlayer.tsx index 9a486b4..db81ecf 100644 --- a/src/components/AudioPlayer.tsx +++ b/src/components/AudioPlayer.tsx @@ -238,6 +238,8 @@ const AudioPlayer: React.FC< audio.ontimeupdate = ontimeupdate; audio.onvolumechange = onvolumechange; audio.onwaiting = onwaiting; + + audio.addEventListener("ended", onAudioEnded); setBlob(blob); return blob; }) @@ -248,8 +250,18 @@ const AudioPlayer: React.FC< setDuration(buffer.duration); }); }); + + return () => { + // clean up + audio.removeEventListener("ended", onAudioEnded); + }; }, []); + const onAudioEnded = (): void => { + setIsPlaying(false); + setAudioTime(0); + }; + const playAudio = (): void => { if (!audio.src) return; if (audio.duration !== Infinity) setDuration(audio.duration); diff --git a/src/main.tsx b/src/main.tsx index cfe381c..3112ebd 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -5,7 +5,7 @@ import { AudioPlayer } from "./components/AudioPlayer"; ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render( console.log("ENDED")} // seekBarColor="purple" // volumeControlColor="blue" // hideSeekBar={true}