Web player fixes

This commit is contained in:
jeffvli
2022-11-12 18:45:25 -08:00
parent 8353640d05
commit 81fafd20d3
2 changed files with 9 additions and 20 deletions
@@ -78,13 +78,13 @@ export const AudioPlayer = forwardRef(
useEffect(() => { useEffect(() => {
if (status === PlayerStatus.PLAYING) { if (status === PlayerStatus.PLAYING) {
if (currentPlayer === 1) { if (currentPlayer === 1) {
player1Ref.current.getInternalPlayer().play(); player1Ref.current?.getInternalPlayer()?.play();
} else { } else {
player2Ref.current.getInternalPlayer().play(); player2Ref.current?.getInternalPlayer()?.play();
} }
} else { } else {
player1Ref.current.getInternalPlayer().pause(); player1Ref.current?.getInternalPlayer()?.pause();
player2Ref.current.getInternalPlayer().pause(); player2Ref.current?.getInternalPlayer()?.pause();
} }
}, [currentPlayer, status]); }, [currentPlayer, status]);
@@ -113,24 +113,12 @@ export const useCenterControls = (args: { playersRef: any }) => {
}, [repeat, setRepeat]); }, [repeat, setRepeat]);
const checkIsLastTrack = useCallback(() => { const checkIsLastTrack = useCallback(() => {
const currentIndex = return usePlayerStore.getState().checkIsLastTrack();
shuffle === PlayerShuffle.NONE }, []);
? usePlayerStore.getState().current.index
: usePlayerStore.getState().current.shuffledIndex;
const queueLength = queue.length;
return currentIndex >= queueLength - 1;
}, [queue.length, shuffle]);
const checkIsFirstTrack = useCallback(() => { const checkIsFirstTrack = useCallback(() => {
const currentIndex = return usePlayerStore.getState().checkIsFirstTrack();
shuffle === PlayerShuffle.NONE }, []);
? usePlayerStore.getState().current.index
: usePlayerStore.getState().current.shuffledIndex;
return currentIndex === 0;
}, [shuffle]);
const handleAutoNext = useCallback(() => { const handleAutoNext = useCallback(() => {
const isLastTrack = checkIsLastTrack(); const isLastTrack = checkIsLastTrack();
@@ -162,6 +150,7 @@ export const useCenterControls = (args: { playersRef: any }) => {
web: () => { web: () => {
if (isLastTrack) { if (isLastTrack) {
resetPlayers(); resetPlayers();
pause();
} else { } else {
autoNext(); autoNext();
resetPlayers(); resetPlayers();