AudioTrack
property
被启用
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.
isAudioEnabled = AudioTrack.enabled; AudioTrack.enabled = true | false;
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.
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;
}
}
swapCommentaryMain()
function above finds within the audio tracks of the
<video>
element
"main-video"
the audio tracks whose
kind
值为
"main"
and
"commentary"
. These represent the primary audio track and the commentary track.
注意: 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
值为
"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.
| 规范 | 状态 | 注释 |
|---|---|---|
|
HTML 实时标准
The definition of 'AudioTrack.enabled' in that specification. |
实时标准 | |
|
HTML5
The definition of 'AudioTrack.enabled' in that specification. |
推荐 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
enabled
|
Chrome
45
Disabled
|
Edge
79
Disabled
|
Firefox 33 | IE 10 |
Opera
32
Disabled
|
Safari 6.1 | WebView Android 45 |
Chrome Android
45
Disabled
|
Firefox Android 33 |
Opera Android
32
Disabled
|
Safari iOS 7 | Samsung Internet Android No |
完整支持
不支持
用户必须明确启用此特征。
AudioTrack
enabled
id
kind
label
语言
sourceBuffer
BeforeUnloadEvent
DOMStringMap
ErrorEvent
GlobalEventHandlers
HTMLAnchorElement
HTMLAreaElement
HTMLAudioElement
HTMLBRElement
HTMLBaseElement
HTMLBaseFontElement
HTMLBodyElement
HTMLButtonElement
HTMLCanvasElement
HTMLContentElement
HTMLDListElement
HTMLDataElement
HTMLDataListElement
HTMLDialogElement
HTMLDivElement
HTMLDocument
HTMLElement
HTMLEmbedElement
HTMLFieldSetElement
HTMLFormControlsCollection
HTMLFormElement
HTMLFrameSetElement
HTMLHRElement
HTMLHeadElement
HTMLHeadingElement
HTMLHtmlElement
HTMLIFrameElement
HTMLImageElement
HTMLInputElement
HTMLIsIndexElement
HTMLKeygenElement
HTMLLIElement
HTMLLabelElement
HTMLLegendElement
HTMLLinkElement
HTMLMapElement
HTMLMediaElement
HTMLMetaElement
HTMLMeterElement
HTMLModElement
HTMLOListElement
HTMLObjectElement
HTMLOptGroupElement
HTMLOptionElement
HTMLOptionsCollection
HTMLOutputElement
HTMLParagraphElement
HTMLParamElement
HTMLPictureElement
HTMLPreElement
HTMLProgressElement
HTMLQuoteElement
HTMLScriptElement
HTMLSelectElement
HTMLShadowElement
HTMLSourceElement
HTMLSpanElement
HTMLStyleElement
HTMLTableCaptionElement
HTMLTableCellElement
HTMLTableColElement
HTMLTableDataCellElement
HTMLTableElement
HTMLTableHeaderCellElement
HTMLTableRowElement
HTMLTableSectionElement
HTMLTemplateElement
HTMLTextAreaElement
HTMLTimeElement
HTMLTitleElement
HTMLTrackElement
HTMLUListElement
HTMLUnknownElement
HTMLVideoElement
HashChangeEvent
历史
ImageData
定位
MessageChannel
MessageEvent
MessagePort
Navigator
NavigatorGeolocation
NavigatorID
NavigatorLanguage
NavigatorOnLine
NavigatorPlugins
PageTransitionEvent
Plugin
PluginArray
PopStateEvent
PortCollection
PromiseRejectionEvent
RadioNodeList
Transferable
ValidityState
Window
WindowBase64
WindowEventHandlers
WindowTimers