From 9ffe81e38b8bb85f6111f11b8b5eafc1b919ac9a Mon Sep 17 00:00:00 2001 From: Julien Maille Date: Fri, 26 Dec 2025 23:15:09 +0100 Subject: [PATCH] improvements --- js/player.js | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/js/player.js b/js/player.js index 7d41efe..7c2cf1e 100644 --- a/js/player.js +++ b/js/player.js @@ -353,22 +353,37 @@ export class Player { removeFromQueue(index) { const currentQueue = this.shuffleActive ? this.shuffledQueue : this.queue; - - if (index < 0 || index >= currentQueue.length) return; - - if (this.shuffleActive) { - this.shuffledQueue.splice(index, 1); - } else { - this.queue.splice(index, 1); + + // If removing current track + if (index === this.currentQueueIndex) { + // If playing, we might want to stop or just let it finish? + // For now, let's just remove it. + // If it's the last track, playback will stop naturally or we handle it? } - + if (index < this.currentQueueIndex) { this.currentQueueIndex--; - } else if (index === this.currentQueueIndex) { - if (currentQueue.length > 0) { - this.playTrackFromQueue(); - } } + + const removedTrack = currentQueue.splice(index, 1)[0]; + + if (this.shuffleActive) { + // Also remove from original queue + const originalIndex = this.originalQueueBeforeShuffle.findIndex(t => t.id === removedTrack.id); // Simple ID check + if (originalIndex !== -1) { + this.originalQueueBeforeShuffle.splice(originalIndex, 1); + } + } + + this.saveQueueState(); + this.preloadNextTracks(); + } + + clearQueue() { + this.queue = []; + this.shuffledQueue = []; + this.originalQueueBeforeShuffle = []; + this.currentQueueIndex = -1; this.saveQueueState(); }