Javascript DOM HTML Video addTextTrack() Method

Introduction

Add a new text track to the video:

Click the button to add a new text track.

The addTextTrack method is not supported in any major browsers.

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">
  Your browser does not support the video tag.
</video>//ww  w .  j  ava2  s .co 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>

The addTextTrack() method creates and returns a new TextTrack object.

The new TextTrack object is added to the list of text tracks for the video element.

addTextTrack(kind, label, language);

Parameter Values

Value
Description
kind






Set the kind of text track.
Possible values:
"subtitles"
"caption"
"descriptions"
"chapters"
"metadata"
label

A string specifying the label for the text track.
identify the text track for the users
language
A two-letter language code that specifies the language of the text track.

The addTextTrack() method returns a TextTrack Object representing the new text track.




PreviousNext

Related