From f688c7ef5d8b4b97a74162d97508092901311379 Mon Sep 17 00:00:00 2001 From: Hyteq Date: Mon, 23 Jun 2025 09:35:32 +0300 Subject: [PATCH] fix: video player properly reflecting the edited timeline, video start --- .../src/components/editor/preview-panel.tsx | 54 +++++++++++++------ apps/web/src/components/editor/timeline.tsx | 25 +++------ apps/web/src/components/ui/video-player.tsx | 6 ++- 3 files changed, 49 insertions(+), 36 deletions(-) diff --git a/apps/web/src/components/editor/preview-panel.tsx b/apps/web/src/components/editor/preview-panel.tsx index 593758e..74bf5f9 100644 --- a/apps/web/src/components/editor/preview-panel.tsx +++ b/apps/web/src/components/editor/preview-panel.tsx @@ -11,39 +11,59 @@ import { Play, Pause } from "lucide-react"; export function PreviewPanel() { const { tracks } = useTimelineStore(); const { mediaItems } = useMediaStore(); - const { isPlaying, toggle } = usePlaybackStore(); + const { isPlaying, toggle, currentTime } = usePlaybackStore(); - const firstClip = tracks[0]?.clips[0]; - const firstMediaItem = firstClip - ? mediaItems.find((item) => item.id === firstClip.mediaId) + // Find the active clip at the current playback time + const getActiveClip = () => { + for (const track of tracks) { + for (const clip of track.clips) { + const clipStart = clip.startTime; + const clipEnd = clip.startTime + (clip.duration - clip.trimStart - clip.trimEnd); + + if (currentTime >= clipStart && currentTime < clipEnd) { + return clip; + } + } + } + return null; + }; + + const activeClip = getActiveClip(); + const activeMediaItem = activeClip + ? mediaItems.find((item) => item.id === activeClip.mediaId) : null; - const aspectRatio = firstMediaItem?.aspectRatio || 16 / 9; + const aspectRatio = activeMediaItem?.aspectRatio || 16 / 9; const renderContent = () => { - if (!firstMediaItem) { + if (!activeMediaItem || !activeClip) { return (
- Drop media to start editing + {tracks.length === 0 ? "Drop media to start editing" : "No clip at current time"}
); } - if (firstMediaItem.type === "video") { + // Calculate the relative time within the clip (accounting for trim) + const relativeTime = Math.max(0, currentTime - activeClip.startTime + activeClip.trimStart); + + if (activeMediaItem.type === "video") { return ( ); } - if (firstMediaItem.type === "image") { + if (activeMediaItem.type === "image") { return (
🎵
-

{firstMediaItem.name}

+

{activeMediaItem.name}