AudioTrack.enabled

The AudioTrack property enabled specifies whether or not the described audio track is currently enabled for use. If the track is disabled by setting enabled to false, the track is muted and does not produce audio.

Syntax

isAudioEnabled = AudioTrack.enabled;

AudioTrack.enabled = true | false;

Value

The enabled property is a Boolean whose value is true if the track is enabled; enabled tracks produce audio while the media is playing. Setting enabled to false effectively mutes the audio track, preventing it from contributing to the media's audio performance.

Example

This example switches between the main and commentary audio tracks of a media element.

function swapCommentaryMain() {
  var videoElem = document.getElementById("main-video");
  var audioTrackMain;
  var audioTrackCommentary;

  videoElem.audioTracks.forEach(track) {
    if (track.kind === "main") {
      audioTrackMain = track;
    } else if (track.kind === "commentary") {
      audioTrackCommentary = track;
    }
  }

  if (audioTrackMain && audioTrackCommentary) {
    var commentaryEnabled = audioTrackCommentary.enabled;
    audioTrackCommentary.enabled = audioTrackMain.enabled;
    audioTrackMain.enabled = commentaryEnabled;
  }
}

The swapCommentaryMain() function above finds within the audio tracks of the <video> element "main-video" the audio tracks whose kind values are "main" and "commentary". These represent the primary audio track and the commentary track.

Note: This example assumes that there is only one of each kind of track in the video, but this is not necessarily the case.

The element's audio tracks are then scanned through using the JavaScript forEach() method (although the audioTracks property of a media element isn't actually a JavaScript array, it can be accessed like one for the most part).

The scan looks for the tracks whose kind values are "main" and "commentary" and remembers those AudioTrack objects. Once those have been found, the values of the two tracks' enabled properties are exchanged, which results in swapping which of the two tracks is currently active.

Specifications

Specification Status Comment
HTML Living Standard
The definition of 'AudioTrack.enabled' in that specification.
Living Standard  
HTML5
The definition of 'AudioTrack.enabled' in that specification.
Recommendation  

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
enabledChrome Full support 45
Disabled
Full support 45
Disabled
Disabled From version 45: this feature is behind the enable-experimental-web-platform-features preference (needs to be set to enabled). To change preferences in Chrome, visit chrome://flags.
Edge Full support 79
Disabled
Full support 79
Disabled
Disabled From version 79: this feature is behind the enable-experimental-web-platform-features preference (needs to be set to enabled).
No support 12 — 79
Firefox Full support 33
Disabled
Full support 33
Disabled
Disabled From version 33: this feature is behind the media.track.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
IE Full support 10Opera Full support 32
Disabled
Full support 32
Disabled
Disabled From version 32: this feature is behind the enable-experimental-web-platform-features preference (needs to be set to enabled).
Safari Full support 6.1WebView Android Full support 45Chrome Android Full support 45
Disabled
Full support 45
Disabled
Disabled From version 45: this feature is behind the enable-experimental-web-platform-features preference (needs to be set to enabled). To change preferences in Chrome, visit chrome://flags.
Firefox Android Full support 33
Disabled
Full support 33
Disabled
Disabled From version 33: this feature is behind the media.track.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
Opera Android Full support 32
Disabled
Full support 32
Disabled
Disabled From version 32: this feature is behind the enable-experimental-web-platform-features preference (needs to be set to enabled).
Safari iOS Full support 7Samsung Internet Android No support No

Legend

Full support  
Full support
No support  
No support
User must explicitly enable this feature.
User must explicitly enable this feature.