HTML Audio & Video

HTML DOM Audio audioTracks Property

The audioTracks property returns an AudioTrackList object representing all of the audio tracks available in a media element. It is read-only: you cannot replace the list, but you can read individual AudioTrack objects and toggle each track's enabled flag.


Definition and Usage

A single media file can contain several audio tracks, for example different languages or a commentary track. The audioTracks property exposes them as an array-like AudioTrackList, where each AudioTrack has properties such as id, kind, label, language and a writable enabled flag.

Syntax

mediaElement.audioTracks

This returns an AudioTrackList. Its length property tells you how many audio tracks exist, and you can index into it like an array.

Example: listing audio tracks

Reading the AudioTrackList after metadata loads
const video = document.getElementById("myVideo");

video.addEventListener("loadedmetadata", () => {
  const tracks = video.audioTracks;
  console.log("Number of audio tracks:", tracks.length);

  for (let i = 0; i < tracks.length; i++) {
    console.log(tracks[i].language, "-", tracks[i].label);
  }
});

Each entry is an AudioTrack. Setting a track's enabled property to true or false turns that audio track on or off during playback, which is how you build a language switcher.

// Enable the first track, mute all others
const tracks = video.audioTracks;
for (let i = 0; i < tracks.length; i++) {
  tracks[i].enabled = (i === 0);
}
⚠️

Browser support for audioTracks is limited: many browsers return an empty list even for files that contain multiple tracks. Always check tracks.length before relying on it.

Ready to use your HTML skills?

Find web development internships and fresher jobs across India.

Browse Web Dev Internships