HTML Audio/Video DOM addTextTrack() Method

The HTML Video DOM addTextTrack() Method is used to creating or returning 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 specify the Kind of the TextTrack
      Possible values are:

    1. “subtitles”
    2. “caption”
    3. “descriptions”
    4. “chapters”
    5. “metadata”
  • label: It contains a string value which specify the label of a TextTrack
  • language: It contains a two-letter language code which specifying a language of the Texttrack.

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

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>
        HTML DOM addTextTrack() Method
    </title>
</head>
  
<body>
    <center>
        <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>
            var GFG = document.getElementById("gfg");
  
            function myGeeks() {
                var sudo = GFG.addTextTrack("caption");
                sudo.addCue(new TextTrackCue(
                  "Test text", 01.000, 04.000, "", "", "", true));
            }
        </script>
      </center>
</body>
  
</html>

chevron_right


Output:



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.