mirror of
https://github.com/yusufipk/OpenFrame.git
synced 2026-09-11 17:46:06 +00:00
fix(video-player): preserve playback state when seeking to timestamps
This commit is contained in:
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user