Skip to content

Commit

Permalink
Update: handle removing the currentlyPlayingSong
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyshankman committed Nov 16, 2024
1 parent 292eb6f commit da8eb36
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions gapless5.js
Original file line number Diff line number Diff line change
Expand Up @@ -1337,6 +1337,14 @@ function Gapless5(options = {}, deprecated = {}) { // eslint-disable-line no-unu
return;
}

const isCurrentTrack = index === this.playlist.trackNumber;
const wasPlayingCurrentTrack = isCurrentTrack && this.isPlaying();

// If it's the current track, pause playback
if (wasPlayingCurrentTrack) {
this.pause();
}

// If removing a track before the current track, decrement trackNumber
if (index < this.playlist.trackNumber) {
this.playlist.trackNumber--;
Expand All @@ -1351,6 +1359,11 @@ function Gapless5(options = {}, deprecated = {}) { // eslint-disable-line no-unu
this.playlist.sources.splice(index, 1);
this.playlist.shuffledIndices = [];
this.uiDirty = true;

// If we were playing and there are tracks remaining, play the next available track
if (wasPlaying && this.playlist.numTracks() > 0) {
this.play();
}
};

/**
Expand Down

0 comments on commit da8eb36

Please sign in to comment.