useProgressBar
Low-level drag state for a raw HTMLVideoElement progress bar.
useProgressBar({video}) is a low-level helper for custom scrubber drag handling around a raw HTMLVideoElement.
Important
If you are building on top of a VideoPlayer scope, prefer usePlayerProgress() — it binds to the enclosing player scope and needs no arguments.
Signature
const progressBar = useProgressBar({video});It returns:
progressisDragginghandleDragStart(event)
Example
import {useState} from "react";
import {useProgressBar} from "@rixl/media-react";
function NativeVideoProgress() {
const [video, setVideo] = useState<HTMLVideoElement | null>(null);
const {progress, isDragging, handleDragStart} = useProgressBar({video});
return (
<div className="space-y-3">
<video ref={setVideo} src="/example.mp4" className="w-full" />
<div role="presentation" className="h-2 rounded bg-gray-200" onMouseDown={handleDragStart} onTouchStart={handleDragStart}>
<div className="h-2 rounded bg-black" style={{width: `${progress * 100}%`}} />
</div>
<div>{isDragging ? "Dragging" : "Idle"}</div>
</div>
);
}Notes
- This hook does not return
duration,isPlaying, or other playback state. - Use it when you need the SDK's drag handling but you already control the raw media element yourself.
Videorefs receive the Lit host. UseusePlayerProgress()inside a player scope for its timeline;useProgressBartargets a rawHTMLVideoElement.- Keep the video element in state through a callback ref so the hook attaches after the element mounts.