getVideoTracks() 方法在 MediaStream interface returns a sequence of MediaStreamTrack objects representing the video tracks in this stream.

句法

var mediaStreamTracks[] = mediaStream.getVideoTracks();
					

参数

None.

返回值

An array of MediaStreamTrack objects, one for each video track contained in the media stream. Video tracks are those tracks whose kind 特性为 视频 . The array is empty if the stream contains no video tracks.

注意: The order of the tracks is not defined by the specification, and may not be the same from one call to getVideoTracks() to another.

Early versions of this API included a special VideoStreamTrack interface which was used as the type for each entry in the list of video streams; however, this has since been merged into the main MediaStreamTrack 接口。

范例

The following example, extracted from Chrome's Image Capture / Photo Resolution Sample , uses getVideoTracks() to retrieve a track for passing to the ImageCapture() 构造函数。

var imageCapture;
navigator.mediaDevices.getUserMedia({video: true})
.then(mediaStream => {
  document.querySelector('video').srcObject = mediaStream;
  const track = mediaStream.getVideoTracks()[0];
  imageCapture = new ImageCapture(track);
  return imageCapture.getPhotoCapabilities();
})
					

规范

规范 状态 注释
媒体捕获和流
The definition of 'getVideoTracks()' in that specification.
候选推荐 初始定义。

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
getVideoTracks Chrome 26 Edge 12 Firefox 22 注意事项
22 注意事项
Prior to Firefox 64, this method returned an array of VideoStreamTrack objects. However, MediaStreamTrack has now subsumed that interface's functionality.
IE 不支持 No Opera Yes Safari Yes WebView Android 37 Chrome Android 26 Firefox Android 22 注意事项
22 注意事项
Prior to Firefox 64, this method returned an array of VideoStreamTrack objects. However, MediaStreamTrack has now subsumed that interface's functionality.
Opera Android 不支持 No Safari iOS Yes Samsung Internet Android 1.5

图例

完整支持

完整支持

不支持

不支持

实验。期望将来行为有所改变。

实验。期望将来行为有所改变。

见实现注意事项。

元数据

  • 最后修改: