English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML Reference Manual

Complete list of HTML tags

HTML Audio/Video DOM textTracks attribute

The read-only textTracks property on the HTMLMediaElement object returns a TextTrackList object, which lists all TextTrack objects representing the text tracks of the media element, in the same order as the text track list.

 HTML Audio/Video DOM Reference Manual

Online example

Get the number of available text tracks:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>HTML Audio/Video textTracks attribute usage-Basic tutorial(oldtoolbag.com)</<title>
</<head>
<body>
<button onclick="getTextTracks()" type="button">Get the number of available text tracks</button>
<br> 
<video id="video1" controls="controls">
  <source src="movie.mp4" type="video/mp4">
  <source src="movie.ogg" type="video/ogg">
  <track src="demo_sub.vtt">
  Your browser does not support HTML5 video tag.
</video>
<script>
myVid=document.getElementById("video1");
function getTextTracks()
{ 
  alert(myVid.textTracks.length);
} 
</script>
</body>
</html>
Test to see ‹/›

Definition and usage

The textTracks property returns a TextTrackList object.
The TextTrackList object represents audio/The available text tracks of the video.
Each available text track is represented by a TextTrack object.

Browser compatibility

IEFirefoxOperaChromeSafari

Internet Explorer 10、Opera、Chrome and Safari 6 Supports the textTracks property.

Note:Internet Explorer 9 And earlier versions do not support the textTracks property.

Syntax

audio|video.textTracks

Return value

TypeDescription
TextTrackList objectRepresents audio/The available text tracks of the video.

TextioTrackList object:

  • length - Get audio/The number of available text tracks in the video

  • [index] - Obtain the TextTrack object based on the index

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

TextTrack objectRepresents a text track.

Properties of the TextTrack object:

  • kind - Get the kind 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

 HTML Audio/Video DOM Reference Manual