From 2344f121cf601d020894da2858236de03258c8ec Mon Sep 17 00:00:00 2001 From: Emad Adel <19177373+emadadel4@users.noreply.github.com> Date: Wed, 25 Sep 2024 07:16:34 +0300 Subject: [PATCH] Update player.js --- assets/js/player.js | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/assets/js/player.js b/assets/js/player.js index 1c876fb..33b8708 100644 --- a/assets/js/player.js +++ b/assets/js/player.js @@ -33,7 +33,6 @@ function playSoura(data) { const audioPlayer = document.getElementById('audioPlayer'); const souraTitle = document.getElementById('souraTitle'); let currentIndex = 0; - let timeUpdateListener = null; const playCurrentSoura = () => { const souraIndex = (startIndex + currentIndex) % data.length; @@ -57,15 +56,10 @@ function playSoura(data) { // Play the audio audioPlayer.play(); - // Remove any previous 'timeupdate' listener before adding a new one - if (timeUpdateListener) { - audioPlayer.removeEventListener('timeupdate', timeUpdateListener); - } - - // Define the new 'timeupdate' listener for the current soura - timeUpdateListener = () => { + // Save the current time of the audio during playback + audioPlayer.addEventListener('timeupdate', () => { localStorage.setItem(`audioTime_${selectedSoura.url}`, audioPlayer.currentTime); - }; + }); // Attach the 'timeupdate' listener for the current soura audioPlayer.addEventListener('timeupdate', timeUpdateListener);