Audio textTracks Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Audio

Description

The textTracks property returns a TextTrackList object, which represents the available text tracks for the audio.

Each available text track is represented by an TextTrack Object.

Return Value

Type Description
TextTrackList Object Represents the available text tracks for the the audio.
TextTrack Object Represents a text track.

TextioTrackList Object has the following properties:

  • length - the number of text tracks available in the audio
  • [index] - TextTrack object by index

The first available TextTrack object is index 0

TextTrack Object has the following Properties:

  • kind - return the type of the text track (can be: "subtitles", "caption", "descriptions", "chapters", or "metadata")
  • label - return the label of the text track
  • language - return 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

The following code shows how to get the number of available text tracks:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<audio id="myAudio" controls>
  <source src="your.ogg" type="audio/ogg">
  <source src="your.mp3" type="audio/mpeg">
  <track src="demo_sub.vtt">
  Your browser does not support the audio element.
</audio>//from   w w  w . j  a va  2 s.  c o m

<p>Click the button to get the number of available text tracks.</p>

<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>

Related Tutorials