Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
emadadel4 committed Sep 25, 2024
1 parent 6fdfa0d commit 332e6dd
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions assets/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ 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;
const selectedSoura = data[souraIndex];
Expand All @@ -56,11 +57,19 @@ function playSoura(data) {
// Play the audio
audioPlayer.play();

// Save the current time of the audio during playback
audioPlayer.addEventListener('timeupdate', () => {
// 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 = () => {
localStorage.setItem(`audioTime_${selectedSoura.url}`, audioPlayer.currentTime);
});
};

// Attach the 'timeupdate' listener for the current soura
audioPlayer.addEventListener('timeupdate', timeUpdateListener);

// Play the next soura once the current one ends
audioPlayer.onended = () => {
currentIndex = (currentIndex + 1) % 3;
Expand Down

0 comments on commit 332e6dd

Please sign in to comment.