Audio addTextTrack() Method - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Audio

Description

The addTextTrack() method creates and returns a new TextTrack object, which is added to the list of text tracks.

Parameter Values

ValueDescription
kind Specifies the kind of text track.
labelA string for the text track to identify the text track for the users
language A two-letter language code to identify the language of the text track.

Possible values for kind:

  • "subtitles"
  • "caption"
  • "descriptions"
  • "chapters"
  • "metadata"

Return Value:

A TextTrack Object, representing the new text track

The following code shows how to Add a new text track to the audio:

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">
  Your browser does not support the audio element.
</audio>//from w ww . ja  v  a 2s.  co  m

<button onclick="myFunction()">Test</button>

<script>
var x = document.getElementById("myAudio");
function myFunction() {
    var y = x.addTextTrack("caption");
    y.addCue(new TextTrackCue("Test text", 01.000, 04.000,"","","",true));
}
</script>

</body>
</html>

Related Tutorials