From e9e9be71f456fbc5e4336f710b1d797a4291822e Mon Sep 17 00:00:00 2001 From: yiling Date: Sun, 14 Jun 2026 21:01:15 +0800 Subject: [PATCH 1/2] refactor(webui): use requestAnimationFrame for smooth video progress bar updates Updates the progress bar currentTime and progress state on requestAnimationFrame loops when playing, while keeping timeupdate as a fallback when paused. --- .../webui/components/viewers/video-player.tsx | 62 ++++++++++++++++--- 1 file changed, 54 insertions(+), 8 deletions(-) diff --git a/packages/webui/components/viewers/video-player.tsx b/packages/webui/components/viewers/video-player.tsx index 64dc9b51..8df702f8 100644 --- a/packages/webui/components/viewers/video-player.tsx +++ b/packages/webui/components/viewers/video-player.tsx @@ -505,15 +505,22 @@ const VideoPlayer: React.FC = ({ setBuffered((bufferedEnd / duration) * 100) } - setState((prev) => ({ - ...prev, - currentTime: current, - duration: duration || prev.duration, - progress: duration > 0 ? (current / duration) * 100 : 0, - })) + // Only update state here if the player is paused. + // When playing, requestAnimationFrame handles smooth updates. + if (player.paused()) { + setState((prev) => { + if (prev.currentTime === current) return prev + return { + ...prev, + currentTime: current, + duration: duration || prev.duration, + progress: duration > 0 ? (current / duration) * 100 : 0, + } + }) - if (onTimeUpdate) { - onTimeUpdate(current) + if (onTimeUpdate) { + onTimeUpdate(current) + } } }) @@ -550,6 +557,45 @@ const VideoPlayer: React.FC = ({ } }, [data]) + // Smooth progress updates using requestAnimationFrame when playing + useEffect(() => { + let animationFrameId: number + + const updateProgress = () => { + const player = playerRef.current + if (player && !player.paused()) { + const current = player.currentTime() || 0 + const duration = player.duration() || data.media?.metadata?.duration || 0 + + setState((prev) => { + if (prev.currentTime === current) return prev + return { + ...prev, + currentTime: current, + duration: duration || prev.duration, + progress: duration > 0 ? (current / duration) * 100 : 0, + } + }) + + if (onTimeUpdate) { + onTimeUpdate(current) + } + + animationFrameId = requestAnimationFrame(updateProgress) + } + } + + if (state.isPlaying) { + animationFrameId = requestAnimationFrame(updateProgress) + } + + return () => { + if (animationFrameId) { + cancelAnimationFrame(animationFrameId) + } + } + }, [state.isPlaying, playerRef, data.media?.metadata?.duration, onTimeUpdate]) + const handleMouseMove = useCallback(() => { // Always show controls on movement setIsControlsVisible(true) From 443b099e1265a5c66a51a489eb24de3c20f126c1 Mon Sep 17 00:00:00 2001 From: yiling Date: Sun, 14 Jun 2026 21:06:39 +0800 Subject: [PATCH 2/2] refactor(webui): move onTimeUpdate out of requestAnimationFrame loop Moves the onTimeUpdate callback back into the native low-frequency timeupdate handler to avoid parent performance degradation, and removes it from the requestAnimationFrame loop and useEffect dependency array. --- packages/webui/components/viewers/video-player.tsx | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/packages/webui/components/viewers/video-player.tsx b/packages/webui/components/viewers/video-player.tsx index 8df702f8..c77b003f 100644 --- a/packages/webui/components/viewers/video-player.tsx +++ b/packages/webui/components/viewers/video-player.tsx @@ -517,10 +517,10 @@ const VideoPlayer: React.FC = ({ progress: duration > 0 ? (current / duration) * 100 : 0, } }) + } - if (onTimeUpdate) { - onTimeUpdate(current) - } + if (onTimeUpdate) { + onTimeUpdate(current) } }) @@ -577,10 +577,6 @@ const VideoPlayer: React.FC = ({ } }) - if (onTimeUpdate) { - onTimeUpdate(current) - } - animationFrameId = requestAnimationFrame(updateProgress) } } @@ -594,7 +590,7 @@ const VideoPlayer: React.FC = ({ cancelAnimationFrame(animationFrameId) } } - }, [state.isPlaying, playerRef, data.media?.metadata?.duration, onTimeUpdate]) + }, [state.isPlaying, playerRef, data.media?.metadata?.duration]) const handleMouseMove = useCallback(() => { // Always show controls on movement