Skip to Content

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

HookPurposeScope
usePlayback()Play, pause, playback rate, and loading stateCurrent player
useMediaSettings()Mute and volumeCurrent player
usePlayerProgress()Timeline, buffered state, and seekingCurrent player
usePlayerTracks()Audio and subtitle tracksCurrent player
usePlayerUI()Controls visibility, fullscreen, and picture-in-pictureCurrent player
useGlobalPlayerSettings()Shared preferences and coordinationShared across players
useProgressBar({video})Pointer seeking for a raw video elementExplicit element

Hooks and callbacks work in React SPAs. In an RSC application such as Next.js, call hooks from your own "use client" component.

Guides