From 4b65d2772866063eed9cb325d2b3ca1995bb8119 Mon Sep 17 00:00:00 2001 From: Mikael Finstad Date: Sun, 6 Oct 2024 16:27:56 +0200 Subject: [PATCH] fix seek jerkiness --- src/renderer/src/hooks/useVideo.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/renderer/src/hooks/useVideo.ts b/src/renderer/src/hooks/useVideo.ts index a1a8dfc2..d245a005 100644 --- a/src/renderer/src/hooks/useVideo.ts +++ b/src/renderer/src/hooks/useVideo.ts @@ -66,10 +66,6 @@ export default ({ filePath }: { filePath: string | undefined }) => { setCompatPlayerEventId((id) => id + 1); // To make sure that we can seek even to the same commanded time that we are already add (e.g. loop current segment) }, [smoothSeek]); - const seekRel = useCallback((val: number) => { - seekAbs(videoRef.current!.currentTime + val); - }, [seekAbs, videoRef]); - const commandedTimeRef = useRef(commandedTime); useEffect(() => { commandedTimeRef.current = commandedTime; @@ -80,6 +76,10 @@ export default ({ filePath }: { filePath: string | undefined }) => { // The reason why we also have a getter is because it can be used when we need to get the time, but don't want to re-render for every time update (which can be heavy!) const getRelevantTime = useCallback(() => (playingRef.current ? videoRef.current!.currentTime : commandedTimeRef.current) || 0, []); + const seekRel = useCallback((val: number) => { + seekAbs(getRelevantTime() + val); + }, [getRelevantTime, seekAbs]); + const onPlayingChange = useCallback((val: boolean) => { playingRef.current = val; setPlaying(val);