mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-09 20:29:36 +02:00
fix(mpv): only check player time when there is an item in the track (#1639)
This commit is contained in:
@@ -12,6 +12,7 @@ import { getMpvProperties } from '/@/renderer/features/settings/components/playb
|
|||||||
import {
|
import {
|
||||||
usePlaybackSettings,
|
usePlaybackSettings,
|
||||||
usePlayerActions,
|
usePlayerActions,
|
||||||
|
usePlayerSong,
|
||||||
usePlayerStore,
|
usePlayerStore,
|
||||||
useSettingsStore,
|
useSettingsStore,
|
||||||
} from '/@/renderer/store';
|
} from '/@/renderer/store';
|
||||||
@@ -49,7 +50,7 @@ export const MpvPlayerEngine = (props: MpvPlayerEngineProps) => {
|
|||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
const [internalVolume, setInternalVolume] = useState(volume / 100 || 0);
|
const [internalVolume, setInternalVolume] = useState(volume / 100 || 0);
|
||||||
const [duration] = useState(0);
|
const currentSong = usePlayerSong();
|
||||||
|
|
||||||
const progressIntervalRef = useRef<NodeJS.Timeout | null>(null);
|
const progressIntervalRef = useRef<NodeJS.Timeout | null>(null);
|
||||||
const isInitializedRef = useRef<boolean>(false);
|
const isInitializedRef = useRef<boolean>(false);
|
||||||
@@ -204,12 +205,18 @@ export const MpvPlayerEngine = (props: MpvPlayerEngineProps) => {
|
|||||||
}
|
}
|
||||||
}, [playerStatus]);
|
}, [playerStatus]);
|
||||||
|
|
||||||
|
const hasCurrentSong = !!currentSong?.id;
|
||||||
|
|
||||||
// Set up progress tracking
|
// Set up progress tracking
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (progressIntervalRef.current) {
|
if (progressIntervalRef.current) {
|
||||||
clearInterval(progressIntervalRef.current);
|
clearInterval(progressIntervalRef.current);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!hasCurrentSong) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const updateProgress = async () => {
|
const updateProgress = async () => {
|
||||||
if (!mpvPlayer || !isMountedRef.current) {
|
if (!mpvPlayer || !isMountedRef.current) {
|
||||||
return;
|
return;
|
||||||
@@ -219,7 +226,7 @@ export const MpvPlayerEngine = (props: MpvPlayerEngineProps) => {
|
|||||||
const time = await mpvPlayer.getCurrentTime();
|
const time = await mpvPlayer.getCurrentTime();
|
||||||
if (time !== undefined && isMountedRef.current) {
|
if (time !== undefined && isMountedRef.current) {
|
||||||
onProgress({
|
onProgress({
|
||||||
played: time / (duration || time + 10),
|
played: time / (time + 10),
|
||||||
playedSeconds: time,
|
playedSeconds: time,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -239,7 +246,7 @@ export const MpvPlayerEngine = (props: MpvPlayerEngineProps) => {
|
|||||||
progressIntervalRef.current = null;
|
progressIntervalRef.current = null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}, [isTransitioning, duration, onProgress]);
|
}, [hasCurrentSong, isTransitioning, onProgress]);
|
||||||
|
|
||||||
const { mediaAutoNext } = usePlayerActions();
|
const { mediaAutoNext } = usePlayerActions();
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ const mpvPlayer = isElectron() ? window.api.mpvPlayer : null;
|
|||||||
|
|
||||||
export function MpvPlayer() {
|
export function MpvPlayer() {
|
||||||
const playerRef = useRef<MpvPlayerEngineHandle>(null);
|
const playerRef = useRef<MpvPlayerEngineHandle>(null);
|
||||||
const { status } = usePlayerData();
|
const { currentSong, status } = usePlayerData();
|
||||||
const { mediaAutoNext, setTimestamp } = usePlayerActions();
|
const { mediaAutoNext, setTimestamp } = usePlayerActions();
|
||||||
const { speed } = usePlayerProperties();
|
const { speed } = usePlayerProperties();
|
||||||
const isMuted = usePlayerMuted();
|
const isMuted = usePlayerMuted();
|
||||||
@@ -147,8 +147,10 @@ export function MpvPlayer() {
|
|||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const hasCurrentSong = !!currentSong?.id;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (localPlayerStatus !== PlayerStatus.PLAYING) {
|
if (localPlayerStatus !== PlayerStatus.PLAYING || !hasCurrentSong) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,7 +170,7 @@ export function MpvPlayer() {
|
|||||||
}, 500);
|
}, 500);
|
||||||
|
|
||||||
return () => clearInterval(interval);
|
return () => clearInterval(interval);
|
||||||
}, [localPlayerStatus, setTimestamp]);
|
}, [hasCurrentSong, localPlayerStatus, setTimestamp]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MpvPlayerEngine
|
<MpvPlayerEngine
|
||||||
|
|||||||
Reference in New Issue
Block a user