diff --git a/packages/webui/components/viewers/video-player.tsx b/packages/webui/components/viewers/video-player.tsx index 64dc9b51..c77b003f 100644 --- a/packages/webui/components/viewers/video-player.tsx +++ b/packages/webui/components/viewers/video-player.tsx @@ -505,12 +505,19 @@ 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) @@ -550,6 +557,41 @@ 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, + } + }) + + animationFrameId = requestAnimationFrame(updateProgress) + } + } + + if (state.isPlaying) { + animationFrameId = requestAnimationFrame(updateProgress) + } + + return () => { + if (animationFrameId) { + cancelAnimationFrame(animationFrameId) + } + } + }, [state.isPlaying, playerRef, data.media?.metadata?.duration]) + const handleMouseMove = useCallback(() => { // Always show controls on movement setIsControlsVisible(true)