Open In App

HTML DOM Audio textTracks Property

Improve
Improve
Like Article
Like
Save
Share
Report

HTML DOM Audio textTracks Property is used for returning a TextTrackList object. The TextTrackList object represents the available text tracks for the audio. Every available text track is represented by a TextTrack Object. 

Syntax:

audioObject.textTracks 

Return Value: It returns a TextTrackList Object Which represents the available text tracks for the audio. TextioTrackList Object is:

  • length: It is used to get the number of text tracks available in the audio
  • [index]: It is used to get TextTrack object by index

Examples: In this example, we will see the use of  DOM Audio textTracks Property.

HTML




<!DOCTYPE html>
<html>
 
<head>
    <title>
          HTML DOM Audio textTracks Property
      </title>
    <style>
        h1 {
            color: green;
        }
        h2 {
            font-family: Impact;
        }
        body {
            text-align: center;
        }
    </style>
</head>
 
<body>
    <h1>GeeksforGeeks</h1>
    <h2>HTML DOM Audio textTracks Property</h2>
    <audio id="track" controls>
        <source src="bells.ogg" type="audio/ogg">
        <source src="bells.mp3" type="audio/mpeg">
        <track src="demo_sub.vtt">
        Your browser does not support the audio element.
    </audio>
    <p>
        Double-click the "Access Audio" button
        to get the duration of the audio, in seconds.
      </p>
    <button onclick="access()">Access Audio</button>
    <p id="test"></p>
   
    <script>
        function access() {
            // Accessing audio element duration.
            let m = document.getElementById(
                "track").textTracks.length;;
            document.getElementById("test").innerHTML = m;
        }
    </script>
</body>
</html>


Output:

 

Supported Browsers: The browser supported by DOM Audio textTracks Property are listed below:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari


Last Updated : 16 Jun, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads