--- title: AudioTrack slug: Web/API/AudioTrack translation_of: Web/API/AudioTrack ---
Das AudioTrack
Interface stellt einen einzelnen Audiotrack aus einem der HTML-Medienelemente {{HTMLElement("audio")}} oder {{HTMLElement("video")}} dar. Die häufigste Verwendung für ein AudioTrack
Objekt ist das (De-)Aktivieren seiner Eigenschaft {{domxref("AudioTrack.enabled", "enabled")}} um den Track stummzuschalten.
false
, ist der Ton stummgeschaltet.kind
die Eigenschaft "main"
.label
"Kommentar mit Regisseur Max Mustermann und den Schauspielern XYZ und ZYX."
Dieser String bleibt leer, wenn kein Label angegeben wurde."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:
var el = document.querySelector("video"); var 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:
var 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(function(track) { if (track.language === userLanguage) { track.enabled = true; } else { track.enabled = false; } });
The {{domxref("AudioTrack.language", "language")}} is in standard ({{RFC(5646)}}) format. For US English, this would be "en-US"
, for example.
{{page("/en-US/docs/Web/API/AudioTrack/label", "Example")}}
Specification | Status | Comment |
---|---|---|
{{SpecName('HTML WHATWG', 'media.html#audiotrack', 'AudioTrack')}} | {{Spec2('HTML WHATWG')}} | |
{{SpecName('HTML5 W3C', 'embedded-content-0.html#audiotrack', 'AudioTrack')}} | {{Spec2('HTML5 W3C')}} |
{{Compat("api.AudioTrack")}}