fix ref error in audio player

This commit is contained in:
Nuwan 2024-12-27 02:12:27 +05:30
parent d7eef09946
commit 6368897b21
1 changed files with 8 additions and 4 deletions

View File

@ -23,7 +23,9 @@ const JKAudioPlayer = ({ audioUrl }) => {
useEffect(() => {
if (!audio || !audioPlayer) return;
stopAudio();
if(audio){
stopAudio();
}
const audioLoadedDataEventListener = audio.addEventListener("loadeddata", () => {
audioPlayer.current.querySelector(".time .length").textContent = getTimeCodeFromNum(
audio.duration
@ -42,9 +44,11 @@ const JKAudioPlayer = ({ audioUrl }) => {
//audio.play();
return () => {
stopAudio();
audio.removeEventListener("loadeddata", audioLoadedDataEventListener);
clearInterval(audioPercentageCheckInterval);
if(audio){
stopAudio();
audio.removeEventListener("loadeddata", audioLoadedDataEventListener);
clearInterval(audioPercentageCheckInterval);
}
}
}, [audio, audioPlayer]);