fix play now

This commit is contained in:
2026-02-10 01:48:02 -08:00
parent c8220eec02
commit 9f0234e00e

View File

@@ -109,22 +109,26 @@ class PlayerStore {
if (existingIdx !== -1) { if (existingIdx !== -1) {
if (playNow) { if (playNow) {
this.playNext(track);
this.playId(track.id); this.playId(track.id);
} }
return; return;
} }
// Add to end
this.queue.push(track);
if (this.isShuffled) {
this.shuffledIndices.push(this.queue.length - 1);
}
if (playNow) { if (playNow) {
this.playNext(track);
this.playId(track.id); this.playId(track.id);
} else if (this.queue.length === 1 && !this.currentId) { } else {
this.currentId = track.id; // Add to end
this.queue.push(track);
if (this.isShuffled) {
this.shuffledIndices.push(this.queue.length - 1);
}
if (this.queue.length === 1 && !this.currentId) {
this.currentId = track.id;
}
} }
} }
@@ -248,23 +252,35 @@ class PlayerStore {
} }
prev() { prev() {
// If history has > 1 item, go back if (this.queue.length === 0) return;
if (this.history.length > 1) {
// Pop current let prevIdxInQueue: number | null = null;
this.history.pop(); const currentIdx = this.currentIndex;
const prevId = this.history[this.history.length - 1];
if (this.hasTrack(prevId)) { if (this.isShuffled) {
this.currentId = prevId; const currentShufflePos = this.shuffledIndices.indexOf(currentIdx);
} else { if (currentShufflePos > 0) {
// Track removed? fallback prevIdxInQueue = this.shuffledIndices[currentShufflePos - 1];
this.history.pop(); // Remove invalid } else if (this.repeatMode === "all" && this.shuffledIndices.length > 0) {
this.prev(); // Recurse // Wrap to end? Or just stop.
// For now let's stop at start if not wrapping.
// If repeat all, wrap to end?
prevIdxInQueue = this.shuffledIndices[this.shuffledIndices.length - 1];
} }
} else { } else {
// Restart current song? if (currentIdx > 0) {
// Handled by UI usually (calling audio.currentTime = 0), prevIdxInQueue = currentIdx - 1;
// but here we just seek to 0 if we could. } else if (this.repeatMode === "all" && this.queue.length > 0) {
// Store doesn't control audio element directly. prevIdxInQueue = this.queue.length - 1;
}
}
if (prevIdxInQueue !== null) {
this.playId(this.queue[prevIdxInQueue]?.id);
} else {
// At start of queue.
// Just seek to 0? Store doesn't control audio.
// If we can't go back, we do nothing (UI likely handles the seek-to-0 comparison).
} }
} }