[bugfix]: improve play behavior

- when adding songs to queue, only `play()` if the queue was empty
- when adding next/last to empty queue, behavior should be same as now
This commit is contained in:
Kendall Garner 2024-02-10 00:38:21 -08:00
parent 0a658e3a22
commit ae8fc6df13
No known key found for this signature in database
GPG key ID: 18D2767419676C87
2 changed files with 9 additions and 3 deletions

View file

@ -167,6 +167,7 @@ export const useHandlePlayQueueAdd = () => {
initialSongIndex = songs.findIndex((song) => song.id === initialSongId);
}
const hadSong = usePlayerStore.getState().queue.default.length > 0;
const playerData = addToQueue({ initialIndex: initialSongIndex, playType, songs });
if (playerType === PlaybackType.LOCAL) {
@ -183,7 +184,11 @@ export const useHandlePlayQueueAdd = () => {
}
}
// We should only play if the queue was empty, or we are doing play NOW
// (override the queue).
if (playType === Play.NOW || !hadSong) {
play();
}
remote?.updateSong({
currentTime: usePlayerStore.getState().current.time,

View file

@ -111,8 +111,10 @@ export const usePlayerStore = create<PlayerSlice>()(
...song,
uniqueId: nanoid(),
}));
const queue = get().queue.default;
if (playType === Play.NOW) {
// If the queue is empty, next/last should behave the same as now
if (playType === Play.NOW || queue.length === 0) {
if (get().shuffle === PlayerShuffle.TRACK) {
const index = initialIndex || 0;
const initialSong = songsToAddToQueue[index];
@ -172,7 +174,6 @@ export const usePlayerStore = create<PlayerSlice>()(
state.queue.shuffled = shuffledQueueWithNewSongs;
});
} else if (playType === Play.NEXT) {
const queue = get().queue.default;
const currentIndex = get().current.index;
if (get().shuffle === PlayerShuffle.TRACK) {