mirror of
https://github.com/jeffvli/feishin.git
synced 2026-06-17 08:54:27 +02:00
fix queue end handling to prevent repeat
This commit is contained in:
@@ -153,6 +153,7 @@ export function WebPlayer() {
|
|||||||
gaplessHandler({
|
gaplessHandler({
|
||||||
currentTime: e.playedSeconds,
|
currentTime: e.playedSeconds,
|
||||||
duration: getDuration(playerRef.current.player1().ref),
|
duration: getDuration(playerRef.current.player1().ref),
|
||||||
|
hasNextSong: Boolean(player2),
|
||||||
isFlac: false,
|
isFlac: false,
|
||||||
isTransitioning,
|
isTransitioning,
|
||||||
nextPlayer: playerRef.current.player2(),
|
nextPlayer: playerRef.current.player2(),
|
||||||
@@ -206,6 +207,7 @@ export function WebPlayer() {
|
|||||||
gaplessHandler({
|
gaplessHandler({
|
||||||
currentTime: e.playedSeconds,
|
currentTime: e.playedSeconds,
|
||||||
duration: getDuration(playerRef.current.player2().ref),
|
duration: getDuration(playerRef.current.player2().ref),
|
||||||
|
hasNextSong: Boolean(player1),
|
||||||
isFlac: false,
|
isFlac: false,
|
||||||
isTransitioning,
|
isTransitioning,
|
||||||
nextPlayer: playerRef.current.player1(),
|
nextPlayer: playerRef.current.player1(),
|
||||||
@@ -680,6 +682,7 @@ function exponentialEaseOut(t: number): number {
|
|||||||
function gaplessHandler(args: {
|
function gaplessHandler(args: {
|
||||||
currentTime: number;
|
currentTime: number;
|
||||||
duration: number;
|
duration: number;
|
||||||
|
hasNextSong: boolean;
|
||||||
isFlac: boolean;
|
isFlac: boolean;
|
||||||
isTransitioning: boolean | string;
|
isTransitioning: boolean | string;
|
||||||
nextPlayer: {
|
nextPlayer: {
|
||||||
@@ -688,7 +691,19 @@ function gaplessHandler(args: {
|
|||||||
};
|
};
|
||||||
setIsTransitioning: Dispatch<boolean | string>;
|
setIsTransitioning: Dispatch<boolean | string>;
|
||||||
}) {
|
}) {
|
||||||
const { currentTime, duration, isFlac, isTransitioning, nextPlayer, setIsTransitioning } = args;
|
const {
|
||||||
|
currentTime,
|
||||||
|
duration,
|
||||||
|
hasNextSong,
|
||||||
|
isFlac,
|
||||||
|
isTransitioning,
|
||||||
|
nextPlayer,
|
||||||
|
setIsTransitioning,
|
||||||
|
} = args;
|
||||||
|
|
||||||
|
if (!hasNextSong) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (!isTransitioning) {
|
if (!isTransitioning) {
|
||||||
if (currentTime > duration - 2) {
|
if (currentTime > duration - 2) {
|
||||||
|
|||||||
@@ -223,7 +223,7 @@ function calculateNextIndex(
|
|||||||
} else {
|
} else {
|
||||||
// Repeat none: move to next track, or pause if at the end
|
// Repeat none: move to next track, or pause if at the end
|
||||||
if (isLastTrack) {
|
if (isLastTrack) {
|
||||||
return { nextIndex: 0, shouldPause: true };
|
return { nextIndex: currentIndex, shouldPause: true };
|
||||||
} else {
|
} else {
|
||||||
return { nextIndex: currentIndex + 1, shouldPause: false };
|
return { nextIndex: currentIndex + 1, shouldPause: false };
|
||||||
}
|
}
|
||||||
@@ -939,10 +939,12 @@ export const usePlayerStoreBase = createWithEqualityFn<PlayerState>()(
|
|||||||
const pauseOnNext = player.pauseOnNextSongEnd;
|
const pauseOnNext = player.pauseOnNextSongEnd;
|
||||||
const newStatus =
|
const newStatus =
|
||||||
shouldPause || pauseOnNext ? PlayerStatus.PAUSED : PlayerStatus.PLAYING;
|
shouldPause || pauseOnNext ? PlayerStatus.PAUSED : PlayerStatus.PLAYING;
|
||||||
|
const shouldKeepCurrentPlayer = newStatus === PlayerStatus.PAUSED;
|
||||||
|
const shouldSwapPlayer = !isRepeatOneSameTrack && !shouldKeepCurrentPlayer;
|
||||||
|
|
||||||
set((state) => {
|
set((state) => {
|
||||||
state.player.index = nextPlaybackIndex;
|
state.player.index = nextPlaybackIndex;
|
||||||
state.player.playerNum = newPlayerNum;
|
state.player.playerNum = shouldSwapPlayer ? newPlayerNum : player.playerNum;
|
||||||
setTimestampStore(0);
|
setTimestampStore(0);
|
||||||
state.player.status = newStatus;
|
state.player.status = newStatus;
|
||||||
|
|
||||||
@@ -999,7 +1001,7 @@ export const usePlayerStoreBase = createWithEqualityFn<PlayerState>()(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { player1, player2 } = getDualPlayerSongs(
|
const { player1, player2 } = getDualPlayerSongs(
|
||||||
newPlayerNum,
|
shouldSwapPlayer ? newPlayerNum : player.playerNum,
|
||||||
currentSong,
|
currentSong,
|
||||||
nextSong,
|
nextSong,
|
||||||
repeat,
|
repeat,
|
||||||
@@ -1009,7 +1011,7 @@ export const usePlayerStoreBase = createWithEqualityFn<PlayerState>()(
|
|||||||
currentSong,
|
currentSong,
|
||||||
index: currentQueueIndex,
|
index: currentQueueIndex,
|
||||||
nextSong,
|
nextSong,
|
||||||
num: newPlayerNum,
|
num: shouldSwapPlayer ? newPlayerNum : player.playerNum,
|
||||||
player1,
|
player1,
|
||||||
player2,
|
player2,
|
||||||
previousSong,
|
previousSong,
|
||||||
|
|||||||
Reference in New Issue
Block a user