Skip to content

ReferenceText tracks

getTextTracks

The text tracks a filter or track definition matches, from the media or the app

Import

import { getTextTracks } from '@videojs/html';

getTextTracks returns the tracks in textTrackList that a filter or track definition matches, from the media and the app alike. Each track’s source says which. The list comes from the text track feature.

A filter picks tracks by kind, label, or language, or with a function. Each given field must match, and a list of kinds matches any kind in it. Without a filter, getTextTracks returns every track.

Usage

Read the tracks in a player.store.subscribe() callback to follow changes:

const player = document.querySelector('video-player')!;

player.store.subscribe(() => {
  const captions = getTextTracks(player.store, { kind: ['captions', 'subtitles'] });
  console.log(captions.map((track) => track.label));
});

API Reference

getTextTracks(source, filter?): MediaTextTrack[]

Parameters

ParameterTypeDefaultDetails
source*object—
filterobject{}

Return Value

MediaTextTrack[]