[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:
parent
0a658e3a22
commit
ae8fc6df13
2 changed files with 9 additions and 3 deletions
|
@ -167,6 +167,7 @@ export const useHandlePlayQueueAdd = () => {
|
||||||
initialSongIndex = songs.findIndex((song) => song.id === initialSongId);
|
initialSongIndex = songs.findIndex((song) => song.id === initialSongId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const hadSong = usePlayerStore.getState().queue.default.length > 0;
|
||||||
const playerData = addToQueue({ initialIndex: initialSongIndex, playType, songs });
|
const playerData = addToQueue({ initialIndex: initialSongIndex, playType, songs });
|
||||||
|
|
||||||
if (playerType === PlaybackType.LOCAL) {
|
if (playerType === PlaybackType.LOCAL) {
|
||||||
|
@ -183,7 +184,11 @@ export const useHandlePlayQueueAdd = () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
play();
|
// 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({
|
remote?.updateSong({
|
||||||
currentTime: usePlayerStore.getState().current.time,
|
currentTime: usePlayerStore.getState().current.time,
|
||||||
|
|
|
@ -111,8 +111,10 @@ export const usePlayerStore = create<PlayerSlice>()(
|
||||||
...song,
|
...song,
|
||||||
uniqueId: nanoid(),
|
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) {
|
if (get().shuffle === PlayerShuffle.TRACK) {
|
||||||
const index = initialIndex || 0;
|
const index = initialIndex || 0;
|
||||||
const initialSong = songsToAddToQueue[index];
|
const initialSong = songsToAddToQueue[index];
|
||||||
|
@ -172,7 +174,6 @@ export const usePlayerStore = create<PlayerSlice>()(
|
||||||
state.queue.shuffled = shuffledQueueWithNewSongs;
|
state.queue.shuffled = shuffledQueueWithNewSongs;
|
||||||
});
|
});
|
||||||
} else if (playType === Play.NEXT) {
|
} else if (playType === Play.NEXT) {
|
||||||
const queue = get().queue.default;
|
|
||||||
const currentIndex = get().current.index;
|
const currentIndex = get().current.index;
|
||||||
|
|
||||||
if (get().shuffle === PlayerShuffle.TRACK) {
|
if (get().shuffle === PlayerShuffle.TRACK) {
|
||||||
|
|
Reference in a new issue