Player hooks
Build custom React controls with player-scoped playback, volume, seeking, audio tracks, subtitles, and UI hooks.
React's player hooks read the scope supplied by Video or VideoPlayer. They take no player ID.
Share a player with custom controls
import {Video, VideoPlayer} from "@rixl/media-react/video";
import {usePlayback} from "@rixl/media-react";
function PlayButton() {
const {paused, togglePlay} = usePlayback();
return (
<button type="button" onClick={() => void togglePlay()}>
{paused ? "Play" : "Pause"}
</button>
);
}
export function Player() {
return (
<VideoPlayer>
<Video id="YOUR_VIDEO_ID" theme="hideUI" style={{display: "block", aspectRatio: "16 / 9"}} />
<PlayButton />
</VideoPlayer>
);
}Initialize the SDK before mounting this player. Keep one Video in each VideoPlayer scope. Controls can also be nested inside Video, which provides its own scope.
Choose a hook
| Hook | Purpose | Scope |
|---|---|---|
usePlayback() | Play, pause, playback rate, and loading state | Current player |
useMediaSettings() | Mute and volume | Current player |
usePlayerProgress() | Timeline, buffered state, and seeking | Current player |
usePlayerTracks() | Audio and subtitle tracks | Current player |
usePlayerUI() | Controls visibility, fullscreen, and picture-in-picture | Current player |
useGlobalPlayerSettings() | Shared preferences and coordination | Shared across players |
useProgressBar({video}) | Pointer seeking for a raw video element | Explicit element |
Hooks and callbacks work in React SPAs. In an RSC application such as Next.js, call hooks from your own "use client" component.