Javascript DOM HTML Audio addTextTrack() Method

Introduction

The addTextTrack method is not supported in any major browsers.

Add a new text track to the audio:

Click the button to add a new text track.

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">
  Your browser does not support the audio element.
</audio>/*  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", 1.0, 4.0,"","","",true));
} 
</script>

</body>
</html>

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

A new TextTrack object is added to the list of text tracks for the audio element.

Parameter Values

Value
Description
kind






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

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



PreviousNext

Related