From 61c172c9cce27f7f062d3fb6fb82f4b040efb35f Mon Sep 17 00:00:00 2001 From: Hyteq Date: Mon, 23 Jun 2025 14:40:34 +0300 Subject: feat: proper video playback including images and videos on the timeline --- apps/web/src/components/editor/timeline.tsx | 65 ++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 2 deletions(-) (limited to 'apps/web/src/components/editor/timeline.tsx') diff --git a/apps/web/src/components/editor/timeline.tsx b/apps/web/src/components/editor/timeline.tsx index d1bb3aa8..1d2df66d 100644 --- a/apps/web/src/components/editor/timeline.tsx +++ b/apps/web/src/components/editor/timeline.tsx @@ -13,6 +13,8 @@ import { MoreVertical, Volume2, VolumeX, + Pause, + Play, } from "lucide-react"; import { Tooltip, @@ -31,10 +33,10 @@ export function Timeline() { // Timeline shows all tracks (video, audio, effects) and their clips. // You can drag media here to add it to your project. // Clips can be trimmed, deleted, and moved. - const { tracks, addTrack, addClipToTrack, removeTrack, toggleTrackMute, removeClipFromTrack, moveClipToTrack } = + const { tracks, addTrack, addClipToTrack, removeTrack, toggleTrackMute, removeClipFromTrack, moveClipToTrack, getTotalDuration } = useTimelineStore(); const { mediaItems, addMediaItem } = useMediaStore(); - const { currentTime, duration, seek } = usePlaybackStore(); + const { currentTime, duration, seek, setDuration, isPlaying, play, pause, toggle } = usePlaybackStore(); const [isDragOver, setIsDragOver] = useState(false); const [isProcessing, setIsProcessing] = useState(false); const [zoomLevel, setZoomLevel] = useState(1); @@ -50,6 +52,12 @@ export function Timeline() { y: number; } | null>(null); + // Update timeline duration when tracks change + useEffect(() => { + const totalDuration = getTotalDuration(); + setDuration(Math.max(totalDuration, 10)); // Minimum 10 seconds for empty timeline + }, [tracks, setDuration, getTotalDuration]); + // Close context menu on click elsewhere useEffect(() => { const handleClick = () => setContextMenu(null); @@ -208,6 +216,59 @@ export function Timeline() { {/* Toolbar */}
+ {/* Play/Pause Button */} + + + + + {isPlaying ? "Pause (Space)" : "Play (Space)"} + + +
+ + {/* Time Display */} +
+ {Math.floor(currentTime * 10) / 10}s / {Math.floor(duration * 10) / 10}s +
+ +
+ + {/* Test Clip Button - for debugging */} + {tracks.length === 0 && ( + + + + + Add a test clip to try playback + + )} + +
+