diff --git a/src/main/frontend/views/video/{id}.tsx b/src/main/frontend/views/video/{id}.tsx index c280317..a4f7d54 100644 --- a/src/main/frontend/views/video/{id}.tsx +++ b/src/main/frontend/views/video/{id}.tsx @@ -1,35 +1,60 @@ import { useParams } from 'react-router-dom'; import { useEffect, useRef, useState } from "react"; import RangeSlider from 'react-range-slider-input'; - import 'react-range-slider-input/dist/style.css'; +export type VideoMetadata = { + startPoint: number, + endPoint: number, + fps: number, + width: number, + height: number, + fileSize: number +} + +const fetchMetadata = async (id: string): Promise => { + const res = await fetch(`/api/v1/metadata/original/${id}`); + if (!res.ok) throw new Error("Failed to fetch"); + return res.json(); +}; + export default function video() { const { id } = useParams(); const videoRef = useRef(null); const videoUrl = "api/v1/download/input/" + id; - const [videoDuration, setVideoDuration] = useState(0); + + const [metadata, setMetadata] = useState(null); + + let previousInput = [0, 0]; + const handleInput = (val: [number, number]) => { + if (!videoRef.current) { + return; + } + + if (previousInput[0] != val[0]) { + videoRef.current.currentTime = val[0]; + } else if (previousInput[1] != val[1]) { + videoRef.current.currentTime = val[1]; + } + + previousInput = val; + }; useEffect(() => { - const videoEl = videoRef.current; - - if (!videoEl) return; - - const handleLoadedMetadata = () => { - setVideoDuration(videoEl.duration); - }; - - videoEl.addEventListener("loadedmetadata", handleLoadedMetadata); - - return () => { - videoEl.removeEventListener("loadedmetadata", handleLoadedMetadata); - }; - }, [videoUrl]); + fetch(`api/v1/metadata/original/${id}`) + .then((res) => { + if (!res.ok) throw new Error("Failed to fetch metadata"); + return res.json(); + }) + .then(setMetadata) + .catch((err) => console.log(err.message)); + }, []); return (
- - + + {metadata && + + }
); } \ No newline at end of file