HTML DOM Track kind Property


The HTML DOM Track kind property sets/returns the value of kind attribute of track element to specify the type of text track.

Following is the syntax −

Returning string value

trackObject.kind

Setting kind to stringValue

trackObject.kind = stringValue

Here, “stringValue” can be the following −

stringValue
Details
captions
The captions are translationof dialogue and sound effects (preferable for deaf users)
chapters
It defines the chaptertitles (used for navigating the media resource)
descriptions
It defines a textualdescription of the video content (preferable for blind users)
metadata
It is not visible to theuser and content is used by scripts
subtitles
It is used to displaysubtitles in a video

Let us see an example of Track kind property −

Example

 Live Demo

<!DOCTYPE html>
<html>
<head>
<title>Track kind</title>
<style>
form {
   width:70%;
   margin: 0 auto;
   text-align: center;
   }
   * {
      padding: 2px;
      margin:5px;
   }
   input[type="button"] {
      border-radius: 10px;
   }
</style>
</head>
<body>
   <form>
      <fieldset>
         <legend>Track-kind</legend>
         <video id="videoSelect" controls width="250" src="sample.mp4">
            <track default kind="subtitles" srclang="es" src="sample-es.srt"/>
            <track kind="subtitles" srclang="en" src="sample-en.srt"/>
         </video><br>
         <input type="button" onclick="getTrackDetails()" value="What is the kind of default track?">
         <div id="divDisplay"></div>
      </fieldset>
   </form>
<script>
   var divDisplay = document.getElementById("divDisplay");
   var trackSelect = document.getElementsByTagName("track");
   function getTrackDetails() {
      for(var i=0; i<trackSelect.length; i++)
         if(trackSelect[i].default)
            divDisplay.textContent = 'kind of track for video: '+trackSelect[i].kind;
   }
</script>
</body>
</html>

Output

Before clicking ‘What is the kind of default track?’ button −

After clicking ‘What is the kind of default track?’ button −

Updated on: 29-Oct-2019

63 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements