Open In App

HTML Audio/Video DOM addTextTrack() Method

Last Updated : 15 Jun, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The HTML Video DOM addTextTrack() Method is used to create or return the new TextTrack of a video Element. The new TextTrack is added to the list of all TextTracks of a Video Element. 

Syntax:

audio/video.addTextTrack(kind, label, language)

Parameter Values:

  • Kind: It specifies the Kind of the TextTrack
    • “subtitles”
    • “caption”
    • “descriptions”
    • “chapters”
    • “metadata”
  • label: It contains a string value that specifies the label of a TextTrack
  • language: It contains a two-letter language code that specifies the language of the Texttrack.

Return value: It returns a TextTrack Object which represents a new TextTrack of a Video Element. 

Example: In this example, we will use the HTML Audio/Video DOM addTextTrack() Method

HTML




<!DOCTYPE html>
<html>
   
<head>
    <title>
        HTML DOM addTextTrack() Method
    </title>
</head>
   
<body>
    <h1 style="color:green;">
        GeeksForGeeks
    </h1>
    <h2>
        HTML DOM Video addTextTrack() Method
    </h2>
    <video id="gfg" width="320"
           height="240" controls>
        <source src=
                type="video/mp4">
    </video>
    <br>
    <button type="button" onclick="myGeeks()">
        New Text Track
    </button>
   
    <script>
        let GFG = document.getElementById("gfg");
        function myGeeks() {
            let sudo = GFG.addTextTrack("caption");
            sudo.addCue(new TextTrackCue(
                "Test text", "01.000, 04.000", "", "", "", true));
        }
    </script>
</body>
 
</html>


Output:

 



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads