fix mpv progress interval still running after queue ends

This commit is contained in:
jeffvli
2026-04-03 18:58:58 -07:00
parent 3c42355c1e
commit f3a6027e6d
2 changed files with 15 additions and 3 deletions
+10 -2
View File
@@ -437,10 +437,18 @@ ipcMain.on('player-mute', async (_event, mute: boolean) => {
ipcMain.handle('player-get-time', async (): Promise<number | undefined> => {
try {
return getMpvInstance()?.getTimePosition();
const mpv = getMpvInstance();
if (!mpv) {
return undefined;
}
return await mpv.getTimePosition();
} catch (err: any | NodeMpvError) {
// Err 3: IPC command invalid — e.g. time-pos unavailable when idle / between tracks
if (err?.errcode === 3) {
return undefined;
}
mpvLog({ action: `Failed to get current time` }, err);
return 0;
return undefined;
}
});
@@ -216,6 +216,10 @@ export const MpvPlayerEngine = (props: MpvPlayerEngineProps) => {
return;
}
if (playerStatus !== PlayerStatus.PLAYING) {
return;
}
const updateProgress = async () => {
if (!mpvPlayer || !isMountedRef.current) {
return;
@@ -245,7 +249,7 @@ export const MpvPlayerEngine = (props: MpvPlayerEngineProps) => {
progressIntervalRef.current = null;
}
};
}, [hasCurrentSong, isTransitioning, onProgress]);
}, [hasCurrentSong, isTransitioning, onProgress, playerStatus]);
const { mediaAutoNext } = usePlayerActions();