Media Capture and Streams API (Media Stream)
============================================

該**媒體捕獲和流**API，通常被稱為**媒體流 API**或者乾脆**MediaStream API**，是關係到一個 API的 WebRTC (en-US)提供流式音頻和視頻數據的支持。它提供了用於處理流及其組成軌道的接口和方法，與數據格式關聯的約束，異步使用數據時的成功和錯誤回調以及在此過程中觸發的事件。

概念和用法
-----

該 API 基於`MediaStream` (en-US)對象的操作，該對象代表與音頻或視頻相關的數據流。請參閱「獲取視頻 (en-US)」中的示例。

A `MediaStream` consists of zero or more `MediaStreamTrack` (en-US) objects, representing various audio or video **tracks**. Each `MediaStreamTrack` may have one or more **channels**. The channel represents the smallest unit of a media stream, such as an audio signal associated with a given speaker, like *left* or *right* in a stereo audio track.

`MediaStream` objects have a single **input** and a single **output**. A `MediaStream` object generated by `getUserMedia()` (en-US) is called *local*, and has as its source input one of the user's cameras or microphones. A non-local `MediaStream` may be representing to a media element, like `<video>` (en-US) or `<audio>` (en-US), a stream originating over the network, and obtained via the WebRTC `RTCPeerConnection` (en-US) API, or a stream created using the Web Audio API `MediaStreamAudioSourceNode` (en-US).

The output of the `MediaStream` object is linked to a **consumer**. It can be a media elements, like `<audio>` (en-US) or `<video>` (en-US), the WebRTC `RTCPeerConnection` (en-US) API or a Web Audio API `MediaStreamAudioSourceNode` (en-US).

Interfaces
----------

In these reference articles, you'll find the fundamental information you'll need to know about each of the interfaces that make up the Media Capture and Streams API.

* `BlobEvent` (en-US)
* `CanvasCaptureMediaStreamTrack` (en-US)
* `InputDeviceInfo` (en-US)
* `MediaDeviceKind`
* `MediaDeviceInfo` (en-US)
* `MediaDevices`
* `MediaStream` (en-US)
* `MediaStreamConstraints` (en-US)
* `MediaStreamEvent` (en-US)
* `MediaStreamTrack` (en-US)
* `MediaStreamTrackEvent` (en-US)
* `MediaTrackCapabilities`
* `MediaTrackConstraints` (en-US)
* `MediaTrackSettings` (en-US)
* `MediaTrackSupportedConstraints` (en-US)
* `NavigatorUserMedia`
* `NavigatorUserMediaError`
* `OverconstrainedError` (en-US)
* `URL` (en-US)

Early versions of the Media Capture and Streams API specification included separate `AudioStreamTrack` and `VideoStreamTrack` interfaces—each based upon `MediaStreamTrack` (en-US)—which represented streams of those types. These no longer exist, and you should update any existing code to instead use `MediaStreamTrack` directly.

Events
------

* `addtrack` (en-US)
* `ended` (en-US)
* `mute` (en-US)
* `overconstrained` (en-US)
* `removetrack` (en-US)
* `unmute` (en-US)
Guides and tutorials
--------------------

The articles below provide additional guidance and how-to information that will help you learn to use the API, and how to perform specific tasks that you may wish to handle.

Browser compatibility
---------------------

### api.MediaStream

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

### api.MediaStreamTrack

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

### api.MediaDevices

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

### api.MediaDeviceInfo

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

### api.InputDeviceInfo

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

### api.CanvasCaptureMediaStreamTrack

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

也可以看看
-----

* WebRTC (en-US) -API 簡介頁
* `mediaDevices.getUserMedia()` (en-US)
* 使用 WebRTC 拍攝靜態照片 (en-US)：有關使用`getUserMedia()`。