Video videoTracks Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Video

Description

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.

Return Value

Type Description
VideoTrackList Object Represents the available video tracks for the video.
VideoTrack Object Represents a video track.

VideoTrackList Object:

  • videoTracks.length - get the number of video tracks
  • 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 Properties:

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

The following code shows how to get the number of available video tracks:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<video id="myVideo" width="320" height="240" controls>
  <source src="your.mp4" type="video/mp4">
  <source src="your.ogg" type="video/ogg">
  Your browser does not support the video tag.
</video>//from  w w w.j a v a2s  .c o m

<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>

Related Tutorials