mirror of
https://github.com/jeffvli/feishin.git
synced 2026-08-08 13:23:16 +02:00
fix web player resuming on queue modification (#2250)
- During queue edits, stream URL reloads briefly reported a bogus duration (~0.07s). The gapless handler treated that as near end-of-track and called .play() while the player was still paused
This commit is contained in:
@@ -263,13 +263,15 @@ export const WebPlayerEngine = (props: WebPlayerEngineProps) => {
|
||||
networkRetryCount2.current = 0;
|
||||
}, [src1, src2]);
|
||||
|
||||
// When not transitioning, ensure only the active player can play (e.g. after seek/prev during transition)
|
||||
// When not playing, always pause both players — even during a transition
|
||||
useEffect(() => {
|
||||
if (isTransitioning) return;
|
||||
if (playerStatus !== PlayerStatus.PLAYING) {
|
||||
pauseBothPlayers();
|
||||
return;
|
||||
}
|
||||
if (isTransitioning) {
|
||||
return;
|
||||
}
|
||||
if (playerNum === 1) {
|
||||
player2Ref.current?.getInternalPlayer()?.pause();
|
||||
} else {
|
||||
|
||||
@@ -136,6 +136,10 @@ export function WebPlayer() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (usePlayerStoreBase.getState().player.status !== PlayerStatus.PLAYING) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (transitionType) {
|
||||
case PlayerStyle.CROSSFADE:
|
||||
crossfadeHandler({
|
||||
@@ -195,6 +199,10 @@ export function WebPlayer() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (usePlayerStoreBase.getState().player.status !== PlayerStatus.PLAYING) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (transitionType) {
|
||||
case PlayerStyle.CROSSFADE:
|
||||
crossfadeHandler({
|
||||
@@ -286,6 +294,11 @@ export function WebPlayer() {
|
||||
onCurrentSongChange: () => {
|
||||
setIsTransitioning(false);
|
||||
},
|
||||
onPlayerQueueChange: () => {
|
||||
if (usePlayerStoreBase.getState().player.status !== PlayerStatus.PLAYING) {
|
||||
setIsTransitioning(false);
|
||||
}
|
||||
},
|
||||
onPlayerSeekToTimestamp: (properties) => {
|
||||
setIsTransitioning(false);
|
||||
|
||||
@@ -607,6 +620,13 @@ function crossfadeHandler(args: {
|
||||
} = args;
|
||||
const player = `player${playerNum}`;
|
||||
|
||||
if (usePlayerStoreBase.getState().player.status !== PlayerStatus.PLAYING) {
|
||||
if (isTransitioning) {
|
||||
setIsTransitioning(false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// If there is no next song to transition to, ensure we don't enter or stay in a transition
|
||||
if (!hasNextSong) {
|
||||
currentPlayer.setVolume(volume);
|
||||
@@ -714,10 +734,25 @@ function gaplessHandler(args: {
|
||||
setIsTransitioning,
|
||||
} = args;
|
||||
|
||||
if (usePlayerStoreBase.getState().player.status !== PlayerStatus.PLAYING) {
|
||||
if (isTransitioning) {
|
||||
setIsTransitioning(false);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!hasNextSong) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Ignore invalid durations (e.g. during URL load or empty source placeholder)
|
||||
if (!Number.isFinite(duration) || duration < 2) {
|
||||
if (isTransitioning) {
|
||||
setIsTransitioning(false);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!isTransitioning) {
|
||||
if (currentTime > duration - 2) {
|
||||
return setIsTransitioning(true);
|
||||
|
||||
Reference in New Issue
Block a user