VideoTrack

VideoTrack interface represents a single video track from a <video> 元素。 The most common use for accessing a VideoTrack object is to toggle its selected property in order to make it the active video track for its <video> 元素。

特性

selected
A Boolean value which controls whether or not the video track is active. Only a single video track can be active at any given time, so setting this property to true for one track while another track is active will make that other track inactive.
id 只读
A DOMString which uniquely identifies the track within the media. This ID can be used to locate a specific track within a video track list by calling VideoTrackList.getTrackById() . The ID can also be used as the fragment part of the URL if the media supports seeking by media fragment per the Media Fragments URI specification .
kind 只读
A DOMString specifying the category into which the track falls. For example, the main video track would have a kind of "main" .
label 只读
A DOMString providing a human-readable label for the track. For example, a track whose kind is "sign" might have a label of "A sign-language interpretation" . This string is empty if no label is provided.
language 只读
A DOMString specifying the video track's primary language, or an empty string if unknown. The language is specified as a BCP 47 ( RFC 5646 ) language code, such as "en-US" or "pt-BR" .
sourceBuffer 只读
SourceBuffer that created the track. Returns null if the track was not created by a SourceBuffer SourceBuffer has been removed from the MediaSource.sourceBuffers attribute of its parent media source.

Usage notes

To get a VideoTrack for a given media element, use the element's videoTracks property, which returns a VideoTrackList object from which you can get the individual tracks contained in the media:

var el = document.querySelector("video");
var tracks = el.videoTracks;
					

You can then access the media's individual tracks using either array syntax or functions such as forEach() .

This first example gets the first video track on the media:

var firstTrack = tracks[0];
					

The next example scans through all of the media's video tracks, activating the first video track that is in the user's preferred language (taken from a variable userLanguage ).

for (var i = 0; i < tracks.length; i++) {
  if (tracks[i].language === userLanguage) {
    tracks[i].selected = true;
    break;
  }
});
					

language is in standard ( RFC 5646 ) format. For US English, this would be "en-US" , for example.

规范

规范 状态 Comment
HTML Living Standard
The definition of 'VideoTrack' in that specification.
实时标准

浏览器兼容性

更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
VideoTrack Chrome 45
Disabled
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 79
Disabled
79
Disabled
Disabled From version 79: this feature is behind the enable-experimental-web-platform-features preference (needs to be set to enabled ).
不支持 12 — 79
Firefox 33
Disabled
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 10 Opera 32
Disabled
32
Disabled
Disabled From version 32: this feature is behind the enable-experimental-web-platform-features preference (needs to be set to enabled ).
Safari 6.1 WebView Android 45 Chrome Android 45
Disabled
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 33
Disabled
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 32
Disabled
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 7 Samsung Internet Android No
id Chrome 45
Disabled
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 79
Disabled
79
Disabled
Disabled From version 79: this feature is behind the enable-experimental-web-platform-features preference (needs to be set to enabled ).
不支持 12 — 79
Firefox 33
Disabled
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 10 Opera 32
Disabled
32
Disabled
Disabled From version 32: this feature is behind the enable-experimental-web-platform-features preference (needs to be set to enabled ).
Safari 6.1 WebView Android 45 Chrome Android 45
Disabled
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 33
Disabled
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 32
Disabled
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 7 Samsung Internet Android No
kind Chrome 45
Disabled
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 79
Disabled
79
Disabled
Disabled From version 79: this feature is behind the enable-experimental-web-platform-features preference (needs to be set to enabled ).
不支持 12 — 79
Firefox 33
Disabled
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 10 Opera 32
Disabled
32
Disabled
Disabled From version 32: this feature is behind the enable-experimental-web-platform-features preference (needs to be set to enabled ).
Safari 6.1 WebView Android 45 Chrome Android 45
Disabled
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 33
Disabled
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 32
Disabled
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 7 Samsung Internet Android No
label Chrome 45
Disabled
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 79
Disabled
79
Disabled
Disabled From version 79: this feature is behind the enable-experimental-web-platform-features preference (needs to be set to enabled ).
不支持 12 — 79
Firefox 33
Disabled
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 10 Opera 32
Disabled
32
Disabled
Disabled From version 32: this feature is behind the enable-experimental-web-platform-features preference (needs to be set to enabled ).
Safari 6.1 WebView Android 45 Chrome Android 45
Disabled
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 33
Disabled
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 32
Disabled
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 7 Samsung Internet Android No
language Chrome 45
Disabled
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 79
Disabled
79
Disabled
Disabled From version 79: this feature is behind the enable-experimental-web-platform-features preference (needs to be set to enabled ).
不支持 12 — 79
Firefox 33
Disabled
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 10 Opera 32
Disabled
32
Disabled
Disabled From version 32: this feature is behind the enable-experimental-web-platform-features preference (needs to be set to enabled ).
Safari 6.1 WebView Android 45 Chrome Android 45
Disabled
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 33
Disabled
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 32
Disabled
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 7 Samsung Internet Android No
selected Chrome 45
Disabled
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 79
Disabled
79
Disabled
Disabled From version 79: this feature is behind the enable-experimental-web-platform-features preference (needs to be set to enabled ).
不支持 12 — 79
Firefox 33
Disabled
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 10 Opera 32
Disabled
32
Disabled
Disabled From version 32: this feature is behind the enable-experimental-web-platform-features preference (needs to be set to enabled ).
Safari 6.1 WebView Android 45 Chrome Android 45
Disabled
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 33
Disabled
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 32
Disabled
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 7 Samsung Internet Android No
sourceBuffer Chrome 45
Disabled
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 79
Disabled
79
Disabled
Disabled From version 79: this feature is behind the enable-experimental-web-platform-features preference (needs to be set to enabled ).
不支持 12 — 79
Firefox No IE 10 Opera 32
Disabled
32
Disabled
Disabled From version 32: this feature is behind the enable-experimental-web-platform-features preference (needs to be set to enabled ).
Safari 6.1 WebView Android 45 Chrome Android 45
Disabled
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 No Opera Android 32
Disabled
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 7 Samsung Internet Android No

图例

完整支持
完整支持
不支持
不支持
用户必须明确启用此特征。
用户必须明确启用此特征。
  1. VideoTrack
  2. 特性
    1. id
    2. kind
    3. label
    4. language
    5. selected
    6. sourceBuffer
  3. Related pages for HTML DOM
    1. BeforeUnloadEvent
    2. DOMStringMap
    3. ErrorEvent
    4. GlobalEventHandlers
    5. HTMLAnchorElement
    6. HTMLAreaElement
    7. HTMLAudioElement
    8. HTMLBRElement
    9. HTMLBaseElement
    10. HTMLBaseFontElement
    11. HTMLBodyElement
    12. HTMLButtonElement
    13. HTMLCanvasElement
    14. HTMLContentElement
    15. HTMLDListElement
    16. HTMLDataElement
    17. HTMLDataListElement
    18. HTMLDialogElement
    19. HTMLDivElement
    20. HTMLDocument
    21. HTMLElement
    22. HTMLEmbedElement
    23. HTMLFieldSetElement
    24. HTMLFormControlsCollection
    25. HTMLFormElement
    26. HTMLFrameSetElement
    27. HTMLHRElement
    28. HTMLHeadElement
    29. HTMLHeadingElement
    30. HTMLHtmlElement
    31. HTMLIFrameElement
    32. HTMLImageElement
    33. HTMLInputElement
    34. HTMLIsIndexElement
    35. HTMLKeygenElement
    36. HTMLLIElement
    37. HTMLLabelElement
    38. HTMLLegendElement
    39. HTMLLinkElement
    40. HTMLMapElement
    41. HTMLMediaElement
    42. HTMLMetaElement
    43. HTMLMeterElement
    44. HTMLModElement
    45. HTMLOListElement
    46. HTMLObjectElement
    47. HTMLOptGroupElement
    48. HTMLOptionElement
    49. HTMLOptionsCollection
    50. HTMLOutputElement
    51. HTMLParagraphElement
    52. HTMLParamElement
    53. HTMLPictureElement
    54. HTMLPreElement
    55. HTMLProgressElement
    56. HTMLQuoteElement
    57. HTMLScriptElement
    58. HTMLSelectElement
    59. HTMLShadowElement
    60. HTMLSourceElement
    61. HTMLSpanElement
    62. HTMLStyleElement
    63. HTMLTableCaptionElement
    64. HTMLTableCellElement
    65. HTMLTableColElement
    66. HTMLTableDataCellElement
    67. HTMLTableElement
    68. HTMLTableHeaderCellElement
    69. HTMLTableRowElement
    70. HTMLTableSectionElement
    71. HTMLTemplateElement
    72. HTMLTextAreaElement
    73. HTMLTimeElement
    74. HTMLTitleElement
    75. HTMLTrackElement
    76. HTMLUListElement
    77. HTMLUnknownElement
    78. HTMLVideoElement
    79. HashChangeEvent
    80. History
    81. ImageData
    82. Location
    83. MessageChannel
    84. MessageEvent
    85. MessagePort
    86. Navigator
    87. NavigatorGeolocation
    88. NavigatorID
    89. NavigatorLanguage
    90. NavigatorOnLine
    91. NavigatorPlugins
    92. PageTransitionEvent
    93. Plugin
    94. PluginArray
    95. PopStateEvent
    96. PortCollection
    97. PromiseRejectionEvent
    98. RadioNodeList
    99. Transferable
    100. ValidityState
    101. Window
    102. WindowBase64
    103. WindowEventHandlers
    104. WindowTimers