fix(mpv): only check player time when there is an item in the track (#1639)

This commit is contained in:
Kendall Garner
2026-02-03 04:49:34 +00:00
committed by GitHub
parent f998491beb
commit 0620b096db
2 changed files with 15 additions and 6 deletions
@@ -12,6 +12,7 @@ import { getMpvProperties } from '/@/renderer/features/settings/components/playb
import {
usePlaybackSettings,
usePlayerActions,
usePlayerSong,
usePlayerStore,
useSettingsStore,
} from '/@/renderer/store';
@@ -49,7 +50,7 @@ export const MpvPlayerEngine = (props: MpvPlayerEngineProps) => {
} = props;
const [internalVolume, setInternalVolume] = useState(volume / 100 || 0);
const [duration] = useState(0);
const currentSong = usePlayerSong();
const progressIntervalRef = useRef<NodeJS.Timeout | null>(null);
const isInitializedRef = useRef<boolean>(false);
@@ -204,12 +205,18 @@ export const MpvPlayerEngine = (props: MpvPlayerEngineProps) => {
}
}, [playerStatus]);
const hasCurrentSong = !!currentSong?.id;
// Set up progress tracking
useEffect(() => {
if (progressIntervalRef.current) {
clearInterval(progressIntervalRef.current);
}
if (!hasCurrentSong) {
return;
}
const updateProgress = async () => {
if (!mpvPlayer || !isMountedRef.current) {
return;
@@ -219,7 +226,7 @@ export const MpvPlayerEngine = (props: MpvPlayerEngineProps) => {
const time = await mpvPlayer.getCurrentTime();
if (time !== undefined && isMountedRef.current) {
onProgress({
played: time / (duration || time + 10),
played: time / (time + 10),
playedSeconds: time,
});
}
@@ -239,7 +246,7 @@ export const MpvPlayerEngine = (props: MpvPlayerEngineProps) => {
progressIntervalRef.current = null;
}
};
}, [isTransitioning, duration, onProgress]);
}, [hasCurrentSong, isTransitioning, onProgress]);
const { mediaAutoNext } = usePlayerActions();
@@ -23,7 +23,7 @@ const mpvPlayer = isElectron() ? window.api.mpvPlayer : null;
export function MpvPlayer() {
const playerRef = useRef<MpvPlayerEngineHandle>(null);
const { status } = usePlayerData();
const { currentSong, status } = usePlayerData();
const { mediaAutoNext, setTimestamp } = usePlayerActions();
const { speed } = usePlayerProperties();
const isMuted = usePlayerMuted();
@@ -147,8 +147,10 @@ export function MpvPlayer() {
};
}, []);
const hasCurrentSong = !!currentSong?.id;
useEffect(() => {
if (localPlayerStatus !== PlayerStatus.PLAYING) {
if (localPlayerStatus !== PlayerStatus.PLAYING || !hasCurrentSong) {
return;
}
@@ -168,7 +170,7 @@ export function MpvPlayer() {
}, 500);
return () => clearInterval(interval);
}, [localPlayerStatus, setTimestamp]);
}, [hasCurrentSong, localPlayerStatus, setTimestamp]);
return (
<MpvPlayerEngine