files/en-us/web/api/audiotrack/index.md
{{APIRef("HTML DOM")}}
The AudioTrack interface represents a single audio track from one of the HTML media elements, {{HTMLElement("audio")}} or {{HTMLElement("video")}}.
The most common use for accessing an AudioTrack object is to toggle its {{domxref("AudioTrack.enabled", "enabled")}} property in order to mute and unmute the track.
false mutes the track's audio.kind of "main".label of "Commentary with director Christopher Nolan and actors Leonardo DiCaprio and Elliot Page." This string is empty if no label is provided."en-US" or "pt-BR".To get an AudioTrack for a given media element, use the element's {{domxref("HTMLMediaElement.audioTracks", "audioTracks")}} property, which returns an {{domxref("AudioTrackList")}} object from which you can get the individual tracks contained in the media:
const el = document.querySelector("video");
const tracks = el.audioTracks;
You can then access the media's individual tracks using either array syntax or functions such as {{jsxref("Array.forEach", "forEach()")}}.
This first example gets the first audio track on the media:
const firstTrack = tracks[0];
The next example scans through all of the media's audio tracks, enabling any that are in the user's preferred language (taken from a variable userLanguage) and disabling any others.
tracks.forEach((track) => {
track.enabled = track.language === userLanguage;
});
The {{domxref("AudioTrack.language", "language")}} is specified as a valid {{glossary("BCP 47 language tag")}}, for example "en-US" for US English.
See AudioTrack.label for an example that shows how to get an array of track kinds and labels for a specified media element, filtered by kind.
{{Specifications}}
{{Compat}}