fix ref error in audio player
This commit is contained in:
parent
d7eef09946
commit
6368897b21
|
|
@ -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]);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue