The Media Capture and Streams API, often called the Media Streams API or simply MediaStream API, is an API related to WebRTC which provides support for streaming audio and video data. It provides the interfaces and methods for working with the streams and their constituent tracks, the constraints associated with data formats, the success and error callbacks when using the data asynchronously, and the events that are fired during the process.
The API is based on the manipulation of a MediaStream
object representing a flux of audio- or video-related data. See an example in Get the video.
A MediaStream
consists of zero or more MediaStreamTrack
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()
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>
or <audio>
, a stream originating over the network, and obtained via the WebRTC RTCPeerConnection
API, or a stream created using the Web Audio API MediaStreamAudioSourceNode
. The output of the MediaStream
object is linked to a consumer. It can be a media elements, like <audio>
or <video>
, the WebRTC RTCPeerConnection
API or a Web Audio API MediaStreamAudioDestinationNode
.
In these reference articles, you'll find the fundamental information you'll need to know about each of the interfaces and events that make up the Media Capture and Streams API.
BlobEvent
CanvasCaptureMediaStreamTrack
InputDeviceInfo
MediaDeviceKind
MediaDeviceInfo
MediaDevices
MediaStream
MediaStreamConstraints
MediaStreamEvent
MediaStreamTrack
MediaStreamTrackEvent
MediaTrackCapabilities
MediaTrackConstraints
MediaTrackSettings
MediaTrackSupportedConstraints
NavigatorUserMedia
NavigatorUserMediaError
URL
Early versions of the Media Capture and Streams API specification included separate AudioStreamTrack
and VideoStreamTrack
interfaces—each based upon MediaStreamTrack
—which represented streams of those types. These no longer exist, and you should update any existing code to instead use MediaStreamTrack
directly.
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.
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | Yes | Yes | Yes | No | No | ? |
MediaStream |
55 | Yes | 44 | No | 42 | No |
active |
Yes | 12 | 52 | ? | ? | ? |
ended
|
? — 54
|
? | No | ? | ? — 39 | ? |
id |
? — 54 | 12 | 41 | ? | ? — 39 | ? |
onaddtrack |
Yes | 12 | 50 | ? | ? | ? |
onremovetrack |
Yes | 12 | No | ? | ? | ? |
addTrack |
Yes | 12 | 44 | ? | ? | ? |
clone |
Yes | 12 | 48 | ? | ? | ? |
getAudioTracks |
Yes | 12 | ? | ? | Yes | ? |
getTrackById |
Yes | 12 | 49 | No | ? | ? |
getTracks
|
Yes | 12 | ? | ? | Yes | ? |
getVideoTracks
|
Yes | 12 | ? | ? | Yes | ? |
removeTrack |
Yes | 12 | ? | ? | Yes | ? |
label
|
? — 54
|
? | ? | No | No | ? |
stop
|
No | 13 | ? | No | No | ? |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | Yes | Yes | Yes | ? | No | ? | Yes |
MediaStream |
55 | 55 | Yes | 42 | ? | No | 6.0 |
active |
Yes | Yes | Yes | 52 | ? | ? | Yes |
ended
|
? — 54
|
? — 54
|
Yes | No | ? — 39 | ? | Yes |
id |
? — 54 | ? — 54 | Yes | 41 | ? — 39 | ? | Yes |
onaddtrack |
Yes | Yes | Yes | 50 | ? | ? | Yes |
onremovetrack |
Yes | Yes | Yes | No | ? | ? | Yes |
addTrack |
Yes | Yes | Yes | No | ? | ? | Yes |
clone |
Yes | Yes | Yes | 48 | ? | ? | Yes |
getAudioTracks |
Yes | Yes | Yes | ? | ? | ? | Yes |
getTrackById |
Yes | Yes | Yes | 49 | ? | ? | Yes |
getTracks
|
Yes | Yes | Yes | ? | ? | ? | Yes |
getVideoTracks
|
Yes | Yes | Yes | ? | ? | ? | Yes |
removeTrack |
Yes | Yes | ? | ? | ? | ? | Yes |
label
|
? — 54
|
? — 54
|
? | ? | No | ? | Yes |
stop
|
No | No | ? | ? | No | ? | No |
mediaDevices.getUserMedia()
getUserMedia()
.
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Media_Streams_API