Javascript DOM HTML Video videoTracks Property get

Introduction

Get the number of available video tracks:

var x = document.getElementById("myVideo").videoTracks.length;

Click the button to get the number of available video tracks.

The videoTracks property is not supported in any major browsers.

View in separate window

<!DOCTYPE html>
<html>
<body>
<video id="myVideo" width="100" height="100" controls>
  <source src="video.mp4" type="video/mp4">
  <source src="video.ogg" type="video/ogg">
  Your browser does not support the video tag.
</video>//from   w  w  w . ja v a  2  s .  c om
<button onclick="myFunction()">Test</button>
<p id="demo"></p>

<script>
function myFunction() {
  var x = document.getElementById("myVideo").videoTracks.length;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The videoTracks property returns a VideoTrackList object.

The VideoTrackList object represents the available video tracks for the video.

Each available video track is represented by an VideoTrack Object.

VideoTrackList Object represents the available video tracks for the video.

Type Description
videoTracks.lengthget the number of video tracks available in the video
videoTracks.getTrackById(id) get VideoTrack object by id
videoTracks[index] get VideoTrack object by index
videoTracks.selectedIndex get the index of the current VideoTrack object

The first available VideoTrack object is index 0

VideoTrack Object represents a video track.

VideoTrack Object Properties:

Property
Description
id
get the id of the video track
kind







get the type of the video track
"alternative"
"captions"
"main"
"sign"
"subtitles"
"commentary"
""
label
get the label of the video track
language
get the language of the video track
selected
get or set if the track is active (true|false)



PreviousNext

Related