AudioTrackList
方法
getTrackById()
返回第一
AudioTrack
object from the track list whose
id
matches the specified string.
This lets you find a specified track if you know its ID string.
var theTrack = AudioTrackList.getTrackById(id);
id
DOMString
indicating the ID of the track to locate within the track list.
AudioTrack
object indicating the first track found within the
AudioTrackList
whose
id
matches the specified string. If no match is found, this method returns
null
.
The tracks are searched in their natural order; that is, in the order defined by the media resource itself, or, if the resource doesn't define an order, the relative order in which the tracks are declared by the media resource.
This example suggests a hypothetical game in which movies are used as cut-scenes or other key set pieces within the game. Each movie has one audio track for each character, as well as one for the music, sound effects, and so forth. This function allows the game to disable a specific character's audio in order to adjust the movie's performance based on occurrences within the game; if the character's dialog isn't relevant, it gets left out. Obviously that would require some clever graphic design to make work, but... it's a hypothetical game.
function disableCharacter(videoElem, characterName) {
videoElem.audioTracks.getTrackById(characterName).enabled = false;
}
This short function gets the
AudioTrackList
containing the video's audio tracks using
HTMLMediaElement.audioTracks
, then calls
getTrackById()
on it, specifying the character's name. The resulting track's audio is then disabled by setting its
enabled
flag to
false
.
| 规范 | 状态 | 注释 |
|---|---|---|
|
HTML 实时标准
The definition of 'AudioTrackList.getTrackById()' in that specification. |
实时标准 | |
|
HTML5
The definition of 'AudioTrackList.getTrackById()' in that specification. |
推荐 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
getTrackById
|
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 |
完整支持
不支持
用户必须明确启用此特征。
AudioTrackList
getTrackById()
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