HTML Audio/Video DOM textTracks property

Example

Get the number of available text tracks:

myVid=document.getElementById("video1");
alert(myVid.textTracks.length);

Try it yourself

Definition and usage

The textTracks property returns a TextTrackList object.

The TextTrackList object represents the available text tracks of the audio/video.

Each available text track is represented by a TextTrack object.

Browser support

The textTracks property is not supported by all mainstream browsers.

Syntax

audio|video.textTracks

Return value

Type Description
TextTrackList object

Represents the available text tracks of the audio/video

Properties of TextioTrackList object:

  • length - Get the number of available text tracks in the audio/video
  • [index] - Obtain the TextTrack object based on the index

Note:The index of the first available text track is 0.

TextTrack object

Represents a text track.

Properties of TextTrack object:

  • kind - Get the type of the text track (can be "subtitles", "caption", "descriptions", "chapters", or "metadata")
  • label - Get the label of the text track
  • language - Get the language of the text track
  • mode - Get or set whether the track is active ("disabled"|"hidden"|"showing")
  • cues - Get the cues list of the TextTrackCueList object
  • activeCues - Get the current active text track cues in the form of a TextTrackCueList object
  • addCue(cue) - Add a cue to the cues list
  • removeCue(cue) - Remove a cue from the cues list