mirror of
https://github.com/jeffvli/feishin.git
synced 2026-07-12 13:39:58 +02:00
on mediaNext, trigger stop on last track if repeat disabled
This commit is contained in:
@@ -1048,21 +1048,45 @@ export const usePlayerStoreBase = createWithEqualityFn<PlayerState>()(
|
|||||||
const state = get();
|
const state = get();
|
||||||
const currentIndex = state.player.index;
|
const currentIndex = state.player.index;
|
||||||
const player = state.player;
|
const player = state.player;
|
||||||
|
const repeat = player.repeat;
|
||||||
|
const isShuffle = isShuffleEnabled(state);
|
||||||
const queue = state.getQueueOrder();
|
const queue = state.getQueueOrder();
|
||||||
const isLastTrack = currentIndex === queue.items.length - 1;
|
const playbackLength = isShuffle
|
||||||
|
? state.queue.shuffled.length
|
||||||
|
: queue.items.length;
|
||||||
|
|
||||||
let nextIndex: number;
|
if (repeat === PlayerRepeat.ONE) {
|
||||||
|
// Manual next while repeat-one is active should still advance in the queue.
|
||||||
|
const nextIndex = Math.min(playbackLength - 1, currentIndex + 1);
|
||||||
|
|
||||||
if (player.repeat === PlayerRepeat.ALL && isLastTrack) {
|
set((state) => {
|
||||||
// Repeat all: wrap to first track when on last track
|
state.player.index = nextIndex;
|
||||||
nextIndex = 0;
|
state.player.playerNum = 1;
|
||||||
} else if (player.repeat === PlayerRepeat.NONE && isLastTrack) {
|
setTimestampStore(0);
|
||||||
// Repeat none: stay on last track if already there
|
});
|
||||||
nextIndex = currentIndex;
|
|
||||||
} else {
|
eventEmitter.emit('MEDIA_NEXT', {
|
||||||
// Otherwise, advance to next track (including repeat ONE for manual navigation)
|
currentIndex,
|
||||||
// When shuffle is enabled, currentIndex is already the position in the shuffled array
|
nextIndex,
|
||||||
nextIndex = Math.min(queue.items.length - 1, currentIndex + 1);
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { nextIndex, shouldStop } = calculateNextIndex(
|
||||||
|
currentIndex,
|
||||||
|
playbackLength,
|
||||||
|
repeat,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (shouldStop) {
|
||||||
|
set((state) => {
|
||||||
|
state.player.status = PlayerStatus.STOPPED;
|
||||||
|
state.player.playerNum = 1;
|
||||||
|
setTimestampStore(0);
|
||||||
|
state.player.seekToTimestamp = uniqueSeekToTimestamp(0);
|
||||||
|
});
|
||||||
|
emitPlayerStop(get, true);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
set((state) => {
|
set((state) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user