import { useCallback, useRef } from "react"; import { useVideoPlayerState } from "../VideoContext"; export function ProgressControl() { const { videoState } = useVideoPlayerState(); const ref = useRef(null); const watchProgress = `${( (videoState.time / videoState.duration) * 100 ).toFixed(2)}%`; const bufferProgress = `${( (videoState.buffered / videoState.duration) * 100 ).toFixed(2)}%`; const handleClick = useCallback( (e: React.MouseEvent) => { if (!ref.current) return; const rect = ref.current.getBoundingClientRect(); const pos = (e.pageX - rect.left) / ref.current.offsetWidth; videoState.setTime(pos * videoState.duration); }, [videoState, ref] ); return (
); }