mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-10 04:30:25 +02:00
Handle shuffle/repeat playback for web
This commit is contained in:
@@ -75,6 +75,19 @@ export const AudioPlayer = forwardRef(
|
|||||||
setIsTransitioning(false);
|
setIsTransitioning(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (status === PlayerStatus.PLAYING) {
|
||||||
|
if (currentPlayer === 1) {
|
||||||
|
player1Ref.current.getInternalPlayer().play();
|
||||||
|
} else {
|
||||||
|
player2Ref.current.getInternalPlayer().play();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
player1Ref.current.getInternalPlayer().pause();
|
||||||
|
player2Ref.current.getInternalPlayer().pause();
|
||||||
|
}
|
||||||
|
}, [currentPlayer, status]);
|
||||||
|
|
||||||
const handleCrossfade1 = useCallback(
|
const handleCrossfade1 = useCallback(
|
||||||
(e: AudioPlayerProgress) => {
|
(e: AudioPlayerProgress) => {
|
||||||
return crossfadeHandler({
|
return crossfadeHandler({
|
||||||
|
|||||||
@@ -163,7 +163,7 @@ export const useCenterControls = (args: { playersRef: any }) => {
|
|||||||
if (isLastTrack) {
|
if (isLastTrack) {
|
||||||
resetPlayers();
|
resetPlayers();
|
||||||
} else {
|
} else {
|
||||||
next();
|
autoNext();
|
||||||
resetPlayers();
|
resetPlayers();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -179,7 +179,7 @@ export const useCenterControls = (args: { playersRef: any }) => {
|
|||||||
if (isLastTrack) {
|
if (isLastTrack) {
|
||||||
resetPlayers();
|
resetPlayers();
|
||||||
} else {
|
} else {
|
||||||
next();
|
autoNext();
|
||||||
resetPlayers();
|
resetPlayers();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -202,7 +202,6 @@ export const useCenterControls = (args: { playersRef: any }) => {
|
|||||||
}, [
|
}, [
|
||||||
autoNext,
|
autoNext,
|
||||||
checkIsLastTrack,
|
checkIsLastTrack,
|
||||||
next,
|
|
||||||
pause,
|
pause,
|
||||||
play,
|
play,
|
||||||
playerType,
|
playerType,
|
||||||
@@ -258,10 +257,7 @@ export const useCenterControls = (args: { playersRef: any }) => {
|
|||||||
},
|
},
|
||||||
web: () => {
|
web: () => {
|
||||||
if (!isLastTrack) {
|
if (!isLastTrack) {
|
||||||
resetPlayers();
|
|
||||||
} else {
|
|
||||||
next();
|
next();
|
||||||
resetPlayers();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -321,11 +317,11 @@ export const useCenterControls = (args: { playersRef: any }) => {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
web: () => {
|
web: () => {
|
||||||
if (!isFirstTrack) {
|
if (isFirstTrack) {
|
||||||
prev();
|
setCurrentIndex(queue.length - 1);
|
||||||
resetPlayers();
|
resetPlayers();
|
||||||
} else {
|
} else {
|
||||||
setCurrentIndex(queue.length - 1);
|
prev();
|
||||||
resetPlayers();
|
resetPlayers();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -338,12 +334,12 @@ export const useCenterControls = (args: { playersRef: any }) => {
|
|||||||
mpvPlayer.previous();
|
mpvPlayer.previous();
|
||||||
},
|
},
|
||||||
web: () => {
|
web: () => {
|
||||||
if (!isFirstTrack) {
|
if (isFirstTrack) {
|
||||||
prev();
|
|
||||||
resetPlayers();
|
|
||||||
} else {
|
|
||||||
resetPlayers();
|
resetPlayers();
|
||||||
pause();
|
pause();
|
||||||
|
} else {
|
||||||
|
prev();
|
||||||
|
resetPlayers();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -359,13 +355,8 @@ export const useCenterControls = (args: { playersRef: any }) => {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
web: () => {
|
web: () => {
|
||||||
if (!isFirstTrack) {
|
|
||||||
prev();
|
prev();
|
||||||
resetPlayers();
|
resetPlayers();
|
||||||
} else {
|
|
||||||
resetPlayers();
|
|
||||||
pause();
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -384,23 +375,6 @@ export const useCenterControls = (args: { playersRef: any }) => {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (isMpvPlayer) {
|
|
||||||
// if (shuffle === PlayerShuffle.TRACK) {
|
|
||||||
// // const playerData = setCurrentIndex(shuffleTrackPrevious());
|
|
||||||
// // mpvPlayer.setQueue(playerData);
|
|
||||||
// mpvPlayer.previous();
|
|
||||||
// } else if (shuffle === PlayerShuffle.ALBUM) {
|
|
||||||
// } else {
|
|
||||||
// const playerData = prev();
|
|
||||||
// mpvPlayer.setQueue(playerData);
|
|
||||||
// mpvPlayer.previous();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (!isMpvPlayer) {
|
|
||||||
// resetPlayers();
|
|
||||||
// }
|
|
||||||
|
|
||||||
return setCurrentTime(0);
|
return setCurrentTime(0);
|
||||||
}, [
|
}, [
|
||||||
checkIsFirstTrack,
|
checkIsFirstTrack,
|
||||||
@@ -483,40 +457,14 @@ export const useCenterControls = (args: { playersRef: any }) => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
ipc?.RENDERER_PLAYER_PLAY_PAUSE(() => {
|
ipc?.RENDERER_PLAYER_PLAY_PAUSE(() => {
|
||||||
handlePlayPause();
|
handlePlayPause();
|
||||||
|
|
||||||
// const { status } = usePlayerStore.getState().current;
|
|
||||||
// if (status === PlayerStatus.PAUSED) {
|
|
||||||
// play();
|
|
||||||
|
|
||||||
// if (isMpvPlayer) {
|
|
||||||
// mpvPlayer.play();
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// pause();
|
|
||||||
// if (isMpvPlayer) {
|
|
||||||
// mpvPlayer.pause();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
});
|
});
|
||||||
|
|
||||||
ipc?.RENDERER_PLAYER_NEXT(() => {
|
ipc?.RENDERER_PLAYER_NEXT(() => {
|
||||||
handleNextTrack();
|
handleNextTrack();
|
||||||
// const playerData = next();
|
|
||||||
|
|
||||||
// if (isMpvPlayer) {
|
|
||||||
// mpvPlayer.setQueue(playerData);
|
|
||||||
// mpvPlayer.next();
|
|
||||||
// }
|
|
||||||
});
|
});
|
||||||
|
|
||||||
ipc?.RENDERER_PLAYER_PREVIOUS(() => {
|
ipc?.RENDERER_PLAYER_PREVIOUS(() => {
|
||||||
handlePrevTrack();
|
handlePrevTrack();
|
||||||
|
|
||||||
// const playerData = prev();
|
|
||||||
// if (isMpvPlayer) {
|
|
||||||
// mpvPlayer.setQueue(playerData);
|
|
||||||
// mpvPlayer.previous();
|
|
||||||
// }
|
|
||||||
});
|
});
|
||||||
|
|
||||||
ipc?.RENDERER_PLAYER_PLAY(() => handlePlay());
|
ipc?.RENDERER_PLAYER_PLAY(() => handlePlay());
|
||||||
@@ -529,12 +477,6 @@ export const useCenterControls = (args: { playersRef: any }) => {
|
|||||||
|
|
||||||
ipc?.RENDERER_PLAYER_AUTO_NEXT(() => {
|
ipc?.RENDERER_PLAYER_AUTO_NEXT(() => {
|
||||||
handleAutoNext();
|
handleAutoNext();
|
||||||
// const playerData = autoNext();
|
|
||||||
// console.log('playerData', playerData);
|
|
||||||
// if (playerData.queue.next) {
|
|
||||||
// mpvPlayer.playerAutoNext(playerData);
|
|
||||||
// play();
|
|
||||||
// }
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
|
|||||||
@@ -249,45 +249,6 @@ export const usePlayerStore = create<PlayerSlice>()(
|
|||||||
status: PlayerStatus.PAUSED,
|
status: PlayerStatus.PAUSED,
|
||||||
time: 0,
|
time: 0,
|
||||||
},
|
},
|
||||||
// getNextTrack: () => {
|
|
||||||
// const shuffle = get().shuffle;
|
|
||||||
// const queue = get().queue.default;
|
|
||||||
// const shuffledQueue = get().queue.shuffled;
|
|
||||||
|
|
||||||
// if (shuffle === PlayerShuffle.TRACK) {
|
|
||||||
|
|
||||||
// }
|
|
||||||
|
|
||||||
// const currentIndex =
|
|
||||||
// shuffle === PlayerShuffle.TRACK
|
|
||||||
// ? get().current.shuffledIndex
|
|
||||||
// : get().current.index;
|
|
||||||
|
|
||||||
// const current = queue.find(
|
|
||||||
// (song) => song.uniqueId === queue[currentIndex]
|
|
||||||
// ) as QueueSong;
|
|
||||||
|
|
||||||
// let nextSongIndex: number | undefined;
|
|
||||||
// if (repeat === PlayerRepeat.ALL) {
|
|
||||||
// if (isLastTrack) nextSongIndex = 0;
|
|
||||||
// else nextSongIndex = currentIndex + 1;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (repeat === PlayerRepeat.ONE) {
|
|
||||||
// nextSongIndex = currentIndex;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (repeat === PlayerRepeat.NONE) {
|
|
||||||
// if (isLastTrack) nextSongIndex = undefined;
|
|
||||||
// else nextSongIndex = currentIndex + 1;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// const next = nextSongIndex
|
|
||||||
// ? (queue.find(
|
|
||||||
// (song) => song.uniqueId === queue[nextSongIndex as number]
|
|
||||||
// ) as QueueSong)
|
|
||||||
// : undefined;
|
|
||||||
// },
|
|
||||||
getPlayerData: () => {
|
getPlayerData: () => {
|
||||||
const queue = get().queue.default;
|
const queue = get().queue.default;
|
||||||
const currentPlayer = get().current.player;
|
const currentPlayer = get().current.player;
|
||||||
|
|||||||
Reference in New Issue
Block a user