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.
When a thumbnail track is present, thumbnailTrackCrossOrigin reports the media element’s CORS mode, or null when the media is not CORS-enabled. Thumbnail reads it to fetch sprite sheets the same way the browser fetched the track.
Import
import { textTrackFeature } from '@videojs/react';import { textTrackFeature } from '@videojs/html';The liveVideoFeatures and videoFeatures feature bundles include this feature.
API Reference
State
| Property | Type | Details |
|---|---|---|
chaptersCues | MediaTextCue[] | |
| ||
thumbnailCues | MediaTextCue[] | |
| ||
thumbnailTrackSrc | string | null | |
| ||
thumbnailTrackCrossOrigin | 'anonymous' | 'use-credentials' | null | |
| ||
textTrackList | MediaTextTrack[] | |
| ||
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, UIElement, selectTextTrack } from '@videojs/html';
import { videoFeatures } from '@videojs/html/video';
const { PlayerController } = createPlayer({ features: videoFeatures });
class CaptionsButton extends UIElement {
readonly #textTracks = new PlayerController(this, selectTextTrack);
}