Javascript DOM HTML Video textTracks Property get

Introduction

Get the number of available text tracks:

var x = document.getElementById("myVideo").textTracks.length;

Click the button to get the number of available text tracks.

View in separate window

<!DOCTYPE html>
<html>
<body>
<video id="myVideo" width="100" height="100" controls>
  <source src="video.mp4" type="video/mp4">
  <source src="video.ogg" type="video/ogg">
  <track src="demo_sub.vtt">
  Your browser does not support the video tag.
</video>// w ww. j  a  v a 2 s . c om
<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {
  var x = document.getElementById("myVideo").textTracks.length;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The textTracks property returns a TextTrackList object.

The TextTrackList object represents the available text tracks for the video.

Each available text track is represented by a TextTrack Object.

TextTrackList Object represents the available text tracks for the the video.

Type Description
lengthget the number of text tracks available in the video
[index] get TextTrack object by index

The first available TextTrack object is index 0

TextTrack Object represents a text track. TextTrack Object Properties:

Type
kind





Description
get the type of the text track
"subtitles"
"caption"
"descriptions"
"chapters"
"metadata"
label
get the label of the text track
language
get the language of the text track
mode
get or set if the track is active ("disabled"|"hidden"|"showing")
cues
get a list of cues as a TextTrackCueList object
activeCues
get the currently active text track cues as a TextTrackCueList object
addCue(cue)
add a cue to the list of cues
removeCue(cue)
remove a cue from the list of cues



PreviousNext

Related