import { makePercentage, makePercentageString, useProgressBar, } from "@/hooks/useProgressBar"; import { useCallback, useRef } from "react"; import { useVideoPlayerState } from "../VideoContext"; export function ProgressControl() { const { videoState } = useVideoPlayerState(); const ref = useRef(null); const commitTime = useCallback( (percentage) => { videoState.setTime(percentage * videoState.duration); }, [videoState] ); const { dragging, dragPercentage, dragMouseDown } = useProgressBar( ref, commitTime ); let watchProgress = makePercentageString( makePercentage((videoState.time / videoState.duration) * 100) ); if (dragging) watchProgress = makePercentageString(makePercentage(dragPercentage)); const bufferProgress = makePercentageString( makePercentage((videoState.buffered / videoState.duration) * 100) ); return (
); }