usePlayerTracks
Read and change player-scoped audio and subtitle track selection.
usePlayerTracks() exposes the current audio and subtitle track selection for the current scoped player.
Use this hook inside Video children, or inside a shared VideoPlayer that contains one Video. The player scope is resolved
automatically.
Signature
const tracks = usePlayerTracks();It returns:
audioTrackavailableAudioTrackssubtitleTrackavailableSubtitleTrackssetAudioTrack(trackIndex)setSubtitleTrack(trackIndex)
Example
import {Video, VideoPlayer, usePlayerTracks} from "@rixl/media-react";
function CustomTrackControls() {
const {audioTrack, availableAudioTracks, subtitleTrack, availableSubtitleTracks, setAudioTrack, setSubtitleTrack} = usePlayerTracks();
return (
<div className="space-y-2">
<label>
Audio
<select value={audioTrack} onChange={(event) => setAudioTrack(Number(event.target.value))}>
{availableAudioTracks.map((track) => (
<option key={track.index} value={track.index}>
{track.label}
</option>
))}
</select>
</label>
<button type="button" onClick={() => setSubtitleTrack(subtitleTrack === -1 ? 0 : -1)}>
{subtitleTrack === -1 ? "Turn captions on" : "Turn captions off"}
</button>
<div>{`Subtitle options: ${availableSubtitleTracks.length}`}</div>
</div>
);
}
function CustomPlayer() {
return (
<VideoPlayer>
<CustomTrackControls />
<Video id="YOUR_VIDEO_ID" theme="hideUI" style={{display: "block", aspectRatio: "16 / 9"}} />
</VideoPlayer>
);
}Notes
- Track arrays can be empty until the stream metadata is ready.
subtitleTrack === -1means subtitles are off.- This hook is intentionally limited to track selection. Global caption styling and caption preference state are outside this API.