Skip to content

Commit

Permalink
Update player.js
Browse files Browse the repository at this point in the history
  • Loading branch information
emadadel4 committed Sep 25, 2024
1 parent 332e6dd commit 2344f12
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions assets/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit 2344f12

Please sign in to comment.