Audio object method addTextTracks() in Javascript
The audio object method addTextTracks() used to create and retrieve a new TextTrack object. It adds new TextTrack object to the list of text tracks for the audio element. It returns a TextTrack object that represents the new text track.
Syntax
 1 <audio>.addTextTrack(<kind>, <label>, <language>)
audio : A audio element object to create and retrieve text track using addTextTrack() method
kind : It specifies the kind of text track that can be subtitles, caption, descriptions, chapters, metadata
label : A string that represents label for the text track and used to identify the text track for the users
language : A two-letter language code that specifies the language of the text track

Language code

A Locale object represents a specific information, notations, interns of geographical, political, or cultural region. In technical term, it forms the information based on selected locale for the user.
Audio method addTextTrack()
 1 <html>
 2 <style>
 3   .container {
 4     margin: 10px 0;
 5   }  
 6 </style>
 7 <body>
 8 	<h1>The Audio Object</h1>
 9 	<h2>Example</h2>
 10 	
 11 	<div>
 12 	  <audio id="audio" controls >
 13 	    <source src="audio.mp3" type="audio/mpeg">
 14 	    Your browser does not support the audio tag.
 15 	  </audio>
 16 	</div>
 17 	<p>
 18 	  <button onclick="access()">Access</button>
 19 	</p>
 20 	<p id="result"></p>
 21 	
 22 	<script>
 23 	function access() {
 24 	  const audio = document.getElementById("audio");
 25 	  const track = audio.addTextTrack("subtitles");
 26 	  track.addCue(new TextTrackCue("Text", 1.000, 4.000, "" ,"" ,"" , true));  
 27 	  const str = `The track is added !`;
 28 	  document.getElementById("result").innerHTML = str;
 29 	}
 30 	</script>
 31 </body>
 32 </html>
Note : The addTextTrack method is not supported in any major browsers.
Audio method addTextTrack()
Privacy Policy
Terms of Service
Disclaimer
Contact us
About us