feat(queue): move shuffle/loop controls into queue drawer, scoped to queue
This commit is contained in:
@@ -27,6 +27,10 @@ export function useAudioPlayer() {
|
||||
const queue = useAppSelector((s) => s.queue);
|
||||
const accessToken = useAppSelector((s) => s.auth.accessToken);
|
||||
const isSetup = useRef(false);
|
||||
// `ended` is registered once below; read the latest loop flag through a ref
|
||||
// so the listener doesn't need to be re-bound on every queue change.
|
||||
const loopRef = useRef(queue.loop);
|
||||
loopRef.current = queue.loop;
|
||||
|
||||
useEffect(() => {
|
||||
if (isSetup.current) return;
|
||||
@@ -41,7 +45,12 @@ export function useAudioPlayer() {
|
||||
dispatch(setDuration(audio.duration || 0));
|
||||
});
|
||||
audio.addEventListener('ended', () => {
|
||||
dispatch(nextTrack());
|
||||
if (loopRef.current) {
|
||||
audio.currentTime = 0;
|
||||
void audio.play();
|
||||
} else {
|
||||
dispatch(nextTrack());
|
||||
}
|
||||
});
|
||||
audio.addEventListener('pause', () => {
|
||||
dispatch(pause());
|
||||
|
||||
Reference in New Issue
Block a user