Text tracks
Subtitles, captions, and chapter track state for the player store
Manages subtitles, captions, chapters, and thumbnail tracks.
A default kind="chapters" track can also divide the time slider into chapter ranges and label the chapter at the current interaction position.
API Reference
State
| Property | Type | Details |
|---|---|---|
chaptersCues | MediaTextCue[] | |
| ||
thumbnailCues | MediaTextCue[] | |
| ||
thumbnailTrackSrc | null | string | |
| ||
thumbnailTrackCrossOrigin | null | 'anonymous' | 'use-credentials' | |
| ||
textTrackList | MediaTextTrack<TextTrackKind>[] | |
| ||
subtitlesShowing | boolean | |
| ||
Actions
| Action | Type | Details |
|---|---|---|
toggleSubtitles | (forceShow: boolean) => boolean | |
| ||
selectSubtitlesTrack | (value: string) => void | |
| ||
Selector
Pass selectTextTrack to usePlayer to subscribe to text track state. Returns undefined if the text tracks feature is not configured.
Pass selectTextTrack to PlayerController to subscribe to text track state. Returns undefined if the text tracks feature is not configured.
import { selectTextTrack, usePlayer } from '@videojs/react';
function CaptionsButton() {
const tracks = usePlayer(selectTextTrack);
if (!tracks) return null;
return (
<button onClick={() => tracks.toggleSubtitles()}>
{tracks.subtitlesShowing ? 'Hide captions' : 'Show captions'}
</button>
);
}import { createPlayer, MediaElement, selectTextTrack } from '@videojs/html';
import { videoFeatures } from '@videojs/html/video';
const { PlayerController, context } = createPlayer({ features: videoFeatures });
class CaptionsButton extends MediaElement {
readonly #textTracks = new PlayerController(this, context, selectTextTrack);
}