fix(video-player): preserve playback state when seeking to timestamps

This commit is contained in:
Yusuf İpek
2026-02-23 18:25:25 +03:00
parent dd884a325c
commit 1708c5c99c
+14 -2
View File
@@ -1452,8 +1452,20 @@ export function VideoPageContent({ mode, videoId, projectId: propProjectId }: Vi
const handleSeekToTimestamp = useCallback((timestamp: number, annotation?: string | null) => { const handleSeekToTimestamp = useCallback((timestamp: number, annotation?: string | null) => {
setCurrentTime(timestamp); setCurrentTime(timestamp);
if (playerRef.current?.seekTo) { if (playerRef.current?.seekTo) {
const playerState = playerRef.current.getPlayerState?.();
const ytPlayingState = window.YT?.PlayerState?.PLAYING ?? 1;
const ytBufferingState = window.YT?.PlayerState?.BUFFERING ?? 3;
const wasPlayingBeforeSeek = typeof playerState === 'number'
? playerState === ytPlayingState || playerState === ytBufferingState
: isPlaying;
playerRef.current.seekTo(timestamp, true); playerRef.current.seekTo(timestamp, true);
playerRef.current.pauseVideo(); // Preserve playback state when seeking so timeline clicks do not force-pause.
if (wasPlayingBeforeSeek) {
playerRef.current.playVideo();
} else {
playerRef.current.pauseVideo();
}
} }
// Show annotation overlay if present // Show annotation overlay if present
if (annotation) { if (annotation) {
@@ -1466,7 +1478,7 @@ export function VideoPageContent({ mode, videoId, projectId: propProjectId }: Vi
} else { } else {
setViewingAnnotation(null); setViewingAnnotation(null);
} }
}, []); }, [isPlaying]);
const handleMuteToggle = useCallback(() => { const handleMuteToggle = useCallback(() => {
if (!playerRef.current) return; if (!playerRef.current) return;