Video addTextTrack() Method - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Video

Description

The addTextTrack() method creates and returns a new TextTrack object which is used in the list of text tracks for the video element.

Parameter Values

ValueDescription
kind kind of text track. Possible values: "subtitles" "caption" "descriptions" "chapters" ?"metadata"
labelA string label for the text track to identify the text track
language A two-letter language code that specifies the language of the text track.

Return Value:

A TextTrack Object, representing the new text track

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

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<video id="myVideo" width="320" height="240" controls>
  <source src="your.mp4" type="video/mp4">
  <source src="your.ogg" type="video/ogg">
  Your browser does not support the video tag.
</video>/*from   w w w . j  a  v  a2s .c o m*/

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

<script>
var x = document.getElementById("myVideo");

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

</body>
</html>

Related Tutorials