English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML Reference Manual

Complete List of HTML Tags

HTML Audio/Video DOM videoTracks attribute

The videoTracks property is a read-only property of HTMLMediaElement, it is a VideoTrackList list, which contains the video tracks of the corresponding media element, and the video track is a VideoTrack type object.

 HTML Audio/Video DOM Reference Manual

Online Example

Get the number of available video tracks:

!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>HTML Audio/Usage of video videoTracks attribute-Basic Tutorial(oldtoolbag.com)</<title>
</<head>
<body>
<button onclick="getVideoTracks()" type="button">Get the number of available video tracks</button>
<br> 
<video id="video1" controls="controls">
  <source src="movie.mp4" type="video/mp4">
  <source src="movie.ogg" type="video/ogg">
  Your browser does not support HTML5 video tag.
</video>
<script>
myVid=document.getElementById("video1");
function getVideoTracks()
{ 
  alert(myVid.videoTracks.length);
} 
</script> 
</body>
</html>
Test and see ‹/›

Definition and usage

The videoTracks property returns a VideoTrackList object.
The VideoTrackList object represents the available video tracks of the video.
Each available video track is represented by a VideoTrack object.

Browser compatibility

IEFirefoxOperaChromeSafari

The videoTracks property is not supported by all mainstream browsers.

Syntax

video.videoTracks

Return value

TypeDescription
VideoTrackList objectRepresents the available video tracks of the video.

VideoTrackList object:

  • videoTracks.length - Get the number of available video tracks in the video

  • videoTracks.getTrackById(id) - Get the VideoTrack object by id

  • videoTracks[index] - Get the VideoTrack object by index index

  • videoTracks.selectedIndex - Get the index of the current VideoTrack object

Note:The index of the first available VideoTrack object index is 0.

VideoTrack objectRepresents a video track.

Properties of VideoTrack object:

  • id - Get the id of the VideoTrack object

  • kind - Get the kind of the video track (can be "alternative", "captions", "main", "sign", "subtitles", "commentary" or "" (empty string))

  • label - Get the label of the video track

  • language - Get the language of the video track

  • selected - Get or set whether the video track is active (true|false)

 HTML Audio/Video DOM Reference Manual