diff options
| author | StarKnightt <prasenjitt4e@gmail.com> | 2025-06-23 20:01:12 +0530 |
|---|---|---|
| committer | StarKnightt <prasenjitt4e@gmail.com> | 2025-06-23 20:01:12 +0530 |
| commit | f72f5c100badb8ad744a20b9110f9f5e7a9bf774 (patch) | |
| tree | fe5a0e9238ee9949efd2255243f31adafd3ff2f6 /apps/web/src/components/ui/video-player.tsx | |
| parent | 294ba01abeb2d8c3d3a04cb7ecc54abf97a6d4d3 (diff) | |
| download | opencut-f72f5c100badb8ad744a20b9110f9f5e7a9bf774.tar.gz | |
Add video speed control and improve playback smoothness
Added a speed control dropdown in the timeline toolbar that lets users change video playback speed between 0.5x to 2x. The dropdown shows the current speed and offers preset options.
Made video playback smoother by:
- Using better timing for speed changes
- Improving video synchronization
- Reducing playback stutters
- Making speed changes more responsive
The speed control is now easily accessible while editing and works smoothly with all video clips.
Diffstat (limited to 'apps/web/src/components/ui/video-player.tsx')
| -rw-r--r-- | apps/web/src/components/ui/video-player.tsx | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/apps/web/src/components/ui/video-player.tsx b/apps/web/src/components/ui/video-player.tsx index 0c4f8498..8731e1a8 100644 --- a/apps/web/src/components/ui/video-player.tsx +++ b/apps/web/src/components/ui/video-player.tsx @@ -25,7 +25,7 @@ export function VideoPlayer({ clipDuration }: VideoPlayerProps) { const videoRef = useRef<HTMLVideoElement>(null); - const { isPlaying, currentTime, volume, play, pause, setVolume } = usePlaybackStore(); + const { isPlaying, currentTime, volume, speed, play, pause, setVolume } = usePlaybackStore(); // Calculate if we're within this clip's timeline range const clipEndTime = clipStartTime + (clipDuration - trimStart - trimEnd); @@ -59,18 +59,26 @@ export function VideoPlayer({ timelineTime - clipStartTime + trimStart )); - // Only sync if there's a significant difference - if (Math.abs(video.currentTime - targetVideoTime) > 0.2) { + // Only sync if there's a significant difference to avoid micro-adjustments + if (Math.abs(video.currentTime - targetVideoTime) > 0.5) { video.currentTime = targetVideoTime; } }; + const handleSpeedEvent = (e: CustomEvent) => { + if (!isInClipRange) return; + // Set playbackRate directly without any additional checks + video.playbackRate = e.detail.speed; + }; + window.addEventListener("playback-seek", handleSeekEvent as EventListener); window.addEventListener("playback-update", handleUpdateEvent as EventListener); + window.addEventListener("playback-speed", handleSpeedEvent as EventListener); return () => { window.removeEventListener("playback-seek", handleSeekEvent as EventListener); window.removeEventListener("playback-update", handleUpdateEvent as EventListener); + window.removeEventListener("playback-speed", handleSpeedEvent as EventListener); }; }, [clipStartTime, trimStart, trimEnd, clipDuration, isInClipRange]); @@ -93,6 +101,13 @@ export function VideoPlayer({ video.volume = volume; }, [volume]); + // Sync speed immediately when it changes + useEffect(() => { + const video = videoRef.current; + if (!video) return; + video.playbackRate = speed; + }, [speed]); + return ( <div className={`relative group ${className}`}> <video @@ -101,7 +116,7 @@ export function VideoPlayer({ poster={poster} className="w-full h-full object-cover" playsInline - preload="metadata" + preload="auto" /> <div className="absolute inset-0 bg-black/20 opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none" /> |
