Skip to content

Commit

Permalink
play/pause working
Browse files Browse the repository at this point in the history
  • Loading branch information
Utkarsh Garg committed Oct 9, 2023
1 parent d1dad93 commit 16918d5
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion script.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,8 @@ let tite = document.getElementById('title');
let download_music = document.getElementById('download_music');
let isPlaying=false;
let pausedTime = 0; // Initialize to 0
let pausedIndex = 0;
let playingIndex = 0;

Array.from(document.getElementsByClassName('playlistplay')).forEach((e)=>{
e.addEventListener('click', (el)=>{
Expand All @@ -350,6 +352,7 @@ Array.from(document.getElementsByClassName('playlistplay')).forEach((e)=>{

music.pause();
pausedTime=music.currentTime;
pausedIndex=playingIndex;
wave.classList.remove('active2');
masterplay.classList.add('bi-play-fill');
masterplay.classList.remove('bi-pause-fill');
Expand All @@ -375,9 +378,15 @@ Array.from(document.getElementsByClassName('playlistplay')).forEach((e)=>{
makeAllBackground();
Array.from(document.getElementsByClassName('songItem'))[index-1].style.background="rgb(105, 105, 170, .1)";

music.currentTime=pausedTime; //Initialize time with paused time.
if(index==pausedIndex){
music.currentTime=pausedTime; //Initialize time with paused time.
}
else{
music.currentTime=0;
}

music.play();
playingIndex=index;
wave.classList.add('active2')
masterplay.classList.remove('bi-play-fill')
masterplay.classList.add('bi-pause-fill')
Expand Down

0 comments on commit 16918d5

Please sign in to comment.