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

HTML Reference Manual

HTML Tag Reference

HTML Audio/Video DOM audioTracks attribute

The AudioTrack interface represents a single track from an HTML media element, <audio> or <video>. The most common use of the AudioTrack object is to switch its enabled attribute to mute and unmute the track.

 HTML Audio/Video DOM Reference Manual

Online example

Get the number of available audio tracks:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>HTML Audio/Video audioTracks attribute usage-Basic tutorial(oldtoolbag.com)</<title>
</<head>
<body>
<button onclick="getAudioTracks()" type="button">Get the number of available audio 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 getAudioTracks()
{ 
  alert(myVid.audioTracks.length);
} 
</script> 
</body>
</html>
Test to see ‹/›

Definition and usage

The audioTracks property returns an AudioTrackList object.
The AudioTrackList object represents audio/The available audio tracks of the video.
Each available track is represented by an AudioTrack object.

Browser compatibility

IEFirefoxOperaChromeSafari

All mainstream browsers do not support the audioTracks property.

Syntax

audio|video.audioTracks

Return value

TypeDescription
AudioTrackList objectRepresents audio/The available audio tracks of the video.

AudioTrackList object:

  • audioTracks.length - Get the number of available audio tracks

  • audioTracks.getTrackById(id) - Get the AudioTrack object by id

  • audioTracks[index] - Get the AudioTrack object by index

Note:The first available AudioTrack object'sIndexis 0.

AudioTrack objectRepresents the audio track.

Properties of AudioTrack object:

  • id - Get the id of the audio track

  • kind - Get the kind of the audio track (can be "alternative", "description", "main", "translation", "commentary" or "" (empty string))

  • label - Get the label of the audio track

  • language - Get the language of the audio track

  • enabled - Get or set whether the audio track is active (true|false)

 HTML Audio/Video DOM Reference Manual