diff --git a/src/components/video-editor.tsx b/src/components/video-editor.tsx index fb77238..0942bb6 100644 --- a/src/components/video-editor.tsx +++ b/src/components/video-editor.tsx @@ -1,15 +1,18 @@ "use client"; -import { useState, useRef, ChangeEvent } from "react"; +import { useState, useRef, ChangeEvent, SyntheticEvent } from "react"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, CardFooter } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; +import { Slider } from "@/components/ui/slider"; import { UploadCloud, Scissors, Download } from "lucide-react"; export function VideoEditor() { const [videoSrc, setVideoSrc] = useState(null); const [videoFile, setVideoFile] = useState(null); + const [duration, setDuration] = useState(0); + const [trimValues, setTrimValues] = useState([0, 0]); const videoRef = useRef(null); const handleFileChange = (event: ChangeEvent) => { @@ -21,6 +24,24 @@ export function VideoEditor() { } }; + const handleLoadedMetadata = (e: SyntheticEvent) => { + const video = e.currentTarget; + setDuration(video.duration); + setTrimValues([0, video.duration]); + }; + + const formatTime = (timeInSeconds: number) => { + if (isNaN(timeInSeconds) || timeInSeconds < 0) { + return "00:00.000"; + } + const minutes = Math.floor(timeInSeconds / 60); + const seconds = Math.floor(timeInSeconds % 60); + const milliseconds = Math.floor((timeInSeconds % 1) * 1000); + return `${String(minutes).padStart(2, "0")}:${String( + seconds + ).padStart(2, "0")}.${String(milliseconds).padStart(3, "0")}`; + }; + return ( @@ -40,13 +61,24 @@ export function VideoEditor() { src={videoSrc} controls className="w-full h-full object-contain bg-black" + onLoadedMetadata={handleLoadedMetadata} />
-

Trim Video

-

- Trimming controls will be added here in the next step. -

+

Trim Video

+
+ +
+ Start: {formatTime(trimValues[0])} + End: {formatTime(trimValues[1])} +
+
) : (