Javascript DOM HTML Audio textTracks Property get

Introduction

Get the number of available text tracks:

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

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

View in separate window

<!DOCTYPE html>
<html>
<body>

<audio id="myAudio" controls>
  <source src="sound.ogg" type="audio/ogg">
  <source src="sound.mp3" type="audio/mpeg">
  <track src="demo_sub.vtt">
  Your browser does not support the audio element.
</audio>/*from w w  w. ja va 2 s  . co m*/
<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {
  var x = document.getElementById("myAudio").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 audio.

Each available text track is represented by an TextTrack Object.

TextioTrackList Object properties:

Value Meaning
length get the number of text tracks available in the audio
[index] get TextTrack object by index

The first available TextTrack object is index 0

TextTrack Object Properties:

Value
Meaning
kind






get the type of the text track
Possible values:
"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
Possible values:
"disabled"
"hidden"
"showing"
cues
get a list of cues as a TextTrackCueList object
activeCues
get the currently active text track 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