HTML DOM Video textTracks Property

HTMLWeb DevelopmentFront End Technology

The HTML DOM Video textTracks property returns a TextTrackList object containing information about the text tracks for the video.

Syntax

Following is the syntax −

Returning TextTracksList Object

mediaObject.textTracks

Let us see an example of Video textTracks property −

Example

<!DOCTYPE html>
<html>
<head>
<title>HTML DOM Video textTracks</title>
<style>
   * {
      padding: 2px;
      margin:5px;
   }
   form {
      width:70%;
      margin: 0 auto;
      text-align: center;
   }
   input[type="button"] {
      border-radius: 10px;
   }
</style>
</head>
<body>
   <form>
      <fieldset>
         <legend>HTML-DOM-Video-textTracks</legend>
         <video id="demo" width="320" controls>
         <source src="http://www.tutorialspoint.com/html5/foo.mp4" type="video/mp4">
         <track default kind="subtitles" srclang="en" src="sample-en.srt" label="English"/>
         <track kind="subtitles" srclang="es" src="sample-es.srt" label="Spanish" />
         </video><br>
         <input type="button" onclick="getTrackDetails()" value="Get Total Text Tracks">
         <div id="divDisplay"></div>
      </fieldset>
   </form>
   <script>
      var divDisplay = document.getElementById("divDisplay");
      var textSelect = document.getElementById("textSelect");
      var demo = document.getElementById("demo");
      function getTrackDetails() {
         divDisplay.textContent = 'Total text tracks '+demo.textTracks.length;
         divDisplay.textContent += ', 1. '+demo.textTracks[0].label;
         divDisplay.textContent += ', 2. '+demo.textTracks[1].label;
      }
   </script>
</body>
</html>

Output

Before clicking ‘Get Total Text Tracks’ button −

After clicking ‘Get Total Text Tracks’ button −

raja
Published on 31-Oct-2019 10:52:25
Advertisements