Skip to content
FrameworkStyle

Text tracks

Subtitles, captions, and chapter track state for the player store

Manages subtitles, captions, chapters, and thumbnail tracks.

API Reference

State

PropertyTypeDetails
chaptersCuesMediaTextCue[]
thumbnailCuesMediaTextCue[]
thumbnailTrackSrcnull | string
textTrackListMediaTextTrack<TextTrackKind>[]
subtitlesShowingboolean

Actions

ActionTypeDetails
toggleSubtitles(forceShow: boolean) => boolean
selectSubtitlesTrack(value: string) => void

Selecting text track state

Pass selectTextTrack to PlayerController to subscribe to text track state. Returns undefined if the text tracks feature is not configured.

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);
}

Selecting one text track

Use a track kind and, when needed, a label to select one track with normalized cues and src details.

import { createPlayer, createTextTrackSelector, MediaElement } from '@videojs/html';
import { videoFeatures } from '@videojs/html/video';

const { PlayerController, context } = createPlayer({ features: videoFeatures });
const selectChapters = createTextTrackSelector('chapters');

class Chapters extends MediaElement {
  readonly #chapters = new PlayerController(this, context, selectChapters);

  get cues() {
    return this.#chapters.value?.cues ?? [];
  }
}