mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-08 13:00:13 +02:00
fix mpv queue initialization running multiple times
This commit is contained in:
@@ -50,6 +50,7 @@ export const MpvPlayerEngine = (props: MpvPlayerEngineProps) => {
|
||||
|
||||
const progressIntervalRef = useRef<NodeJS.Timeout | null>(null);
|
||||
const isInitializedRef = useRef<boolean>(false);
|
||||
const hasPopulatedQueueRef = useRef<boolean>(false);
|
||||
|
||||
const mpvExtraParameters = useSettingsStore((store) => store.playback.mpvExtraParameters);
|
||||
const mpvProperties = useSettingsStore((store) => store.playback.mpvProperties);
|
||||
@@ -85,20 +86,21 @@ export const MpvPlayerEngine = (props: MpvPlayerEngineProps) => {
|
||||
mpvPlayer?.stop();
|
||||
mpvPlayer?.cleanup();
|
||||
isInitializedRef.current = false;
|
||||
hasPopulatedQueueRef.current = false;
|
||||
};
|
||||
}, [mpvExtraParameters, mpvProperties]);
|
||||
|
||||
// Populate mpv queue after initialization
|
||||
useEffect(() => {
|
||||
if (!mpvPlayer || !isInitializedRef.current) {
|
||||
if (!mpvPlayer || !isInitializedRef.current || hasPopulatedQueueRef.current) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentSrc) {
|
||||
const shouldPause = playerStatus !== PlayerStatus.PLAYING;
|
||||
mpvPlayer.setQueue(currentSrc, nextSrc, shouldPause);
|
||||
mpvPlayer.setQueue(currentSrc, nextSrc, true);
|
||||
hasPopulatedQueueRef.current = true;
|
||||
}
|
||||
}, [currentSrc, nextSrc, playerStatus]);
|
||||
}, [currentSrc, nextSrc]);
|
||||
|
||||
// Update volume
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user