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.

Media Capture and Streams Concepts and Usage

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.

Reference

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.

Interfaces

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.

Events

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.

Capabilities, constraints, and settings
The twin concepts of constraints and capabilities let the browser and Web site or app exchange information about what constrainable properties the browser's implementation supports and what values it supports for each one. This article discusses capabilities and constraints, as well as media settings, and includes an example we call the Constraint Exerciser.

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
MediaStreamChrome Full support 14Edge Full support YesFirefox Full support 15IE No support NoOpera Full support YesSafari Full support YesWebView Android Full support 37Chrome Android Full support 18Edge Mobile Full support YesFirefox Android Full support 15Opera Android No support NoSafari iOS Full support YesSamsung Internet Android Full support Yes
MediaStream() constructorChrome Full support 19Edge Full support YesFirefox Full support 44IE No support NoOpera Full support 42Safari No support NoWebView Android Full support 37Chrome Android Full support 25Edge Mobile Full support YesFirefox Android Full support 42Opera Android No support NoSafari iOS No support NoSamsung Internet Android Full support 6.0
activeChrome Full support 45Edge Full support 12Firefox Full support 52IE No support NoOpera No support NoSafari Full support YesWebView Android Full support 45Chrome Android Full support 45Edge Mobile Full support YesFirefox Android Full support 52Opera Android No support NoSafari iOS Full support YesSamsung Internet Android Full support Yes
active_eventChrome Full support 45Edge ? Firefox ? IE ? Opera ? Safari ? WebView Android Full support 45Chrome Android Full support 45Edge Mobile ? Firefox Android ? Opera Android ? Safari iOS ? Samsung Internet Android ?
addtrack eventChrome Full support YesEdge Full support 12Firefox Full support 50IE No support NoOpera No support NoSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 50Opera Android No support NoSafari iOS Full support YesSamsung Internet Android Full support Yes
ended
Deprecated
Chrome No support ? — 54
Notes
No support ? — 54
Notes
Notes Deprecated in Chrome 52.
Edge ? Firefox No support NoIE No support NoOpera No support ? — 39Safari ? WebView Android No support ? — 54
Notes
No support ? — 54
Notes
Notes Deprecated in Chrome 52.
Chrome Android No support ? — 54
Notes
No support ? — 54
Notes
Notes Deprecated in Chrome 52.
Edge Mobile Full support YesFirefox Android No support NoOpera Android No support ? — 41Safari iOS ? Samsung Internet Android Full support Yes
idChrome No support ? — 54Edge Full support 12Firefox Full support 41IE No support NoOpera No support ? — 39Safari Full support YesWebView Android No support ? — 54Chrome Android No support ? — 54Edge Mobile Full support YesFirefox Android Full support 41Opera Android No support ? — 41Safari iOS Full support YesSamsung Internet Android Full support Yes
inactive_eventChrome Full support 45Edge ? Firefox ? IE ? Opera ? Safari ? WebView Android Full support 45Chrome Android Full support 45Edge Mobile ? Firefox Android ? Opera Android ? Safari iOS ? Samsung Internet Android ?
onactiveChrome Full support 45Edge ? Firefox ? IE ? Opera ? Safari ? WebView Android Full support 45Chrome Android Full support 45Edge Mobile ? Firefox Android ? Opera Android ? Safari iOS ? Samsung Internet Android ?
onaddtrackChrome Full support 26Edge Full support 12Firefox Full support 50IE No support NoOpera No support NoSafari Full support YesWebView Android Full support 37Chrome Android Full support 26Edge Mobile Full support YesFirefox Android Full support 50Opera Android No support NoSafari iOS Full support YesSamsung Internet Android Full support Yes
oninactiveChrome Full support 45Edge ? Firefox ? IE ? Opera ? Safari ? WebView Android Full support 45Chrome Android Full support 45Edge Mobile ? Firefox Android ? Opera Android ? Safari iOS ? Samsung Internet Android ?
onremovetrackChrome Full support 26Edge Full support 12Firefox No support NoIE No support NoOpera No support NoSafari Full support YesWebView Android Full support 37Chrome Android Full support 26Edge Mobile Full support YesFirefox Android No support NoOpera Android No support NoSafari iOS Full support YesSamsung Internet Android Full support Yes
addTrackChrome Full support 26Edge Full support 12Firefox Full support 44IE No support NoOpera No support NoSafari Full support YesWebView Android Full support 37Chrome Android Full support 26Edge Mobile Full support YesFirefox Android No support NoOpera Android No support NoSafari iOS Full support YesSamsung Internet Android Full support Yes
cloneChrome Full support 45Edge Full support 12Firefox Full support 48IE No support NoOpera No support NoSafari Full support YesWebView Android Full support 45Chrome Android Full support 45Edge Mobile Full support YesFirefox Android Full support 48Opera Android No support NoSafari iOS Full support YesSamsung Internet Android Full support Yes
getAudioTracksChrome Full support 26Edge Full support 12Firefox Full support 22
Notes
Full support 22
Notes
Notes Prior to Firefox 64, this method returned an array of AudioStreamTrack objects. However, MediaStreamTrack has now subsumed that interface's functionality.
IE No support NoOpera Full support YesSafari Full support YesWebView Android Full support 37Chrome Android Full support 26Edge Mobile Full support YesFirefox Android Full support 22
Notes
Full support 22
Notes
Notes Prior to Firefox 64, this method returned an array of AudioStreamTrack objects. However, MediaStreamTrack has now subsumed that interface's functionality.
Opera Android No support NoSafari iOS Full support YesSamsung Internet Android Full support Yes
getTrackByIdChrome Full support 26Edge Full support 12Firefox Full support 49IE No support NoOpera No support NoSafari Full support YesWebView Android Full support 37Chrome Android Full support 26Edge Mobile Full support YesFirefox Android Full support 49Opera Android No support NoSafari iOS Full support YesSamsung Internet Android Full support Yes
getTracks
Experimental
Chrome Full support 45Edge Full support 12Firefox Full support YesIE No support NoOpera Full support YesSafari Full support YesWebView Android Full support 45Chrome Android Full support 45Edge Mobile Full support YesFirefox Android Full support YesOpera Android No support NoSafari iOS Full support YesSamsung Internet Android Full support Yes
getVideoTracks
Experimental
Chrome Full support 26Edge Full support 12Firefox Full support 22
Notes
Full support 22
Notes
Notes Prior to Firefox 64, this method returned an array of VideoStreamTrack objects. However, MediaStreamTrack has now subsumed that interface's functionality.
IE No support NoOpera Full support YesSafari Full support YesWebView Android Full support 37Chrome Android Full support 26Edge Mobile Full support YesFirefox Android Full support 22
Notes
Full support 22
Notes
Notes Prior to Firefox 64, this method returned an array of VideoStreamTrack objects. However, MediaStreamTrack has now subsumed that interface's functionality.
Opera Android No support NoSafari iOS Full support YesSamsung Internet Android Full support Yes
removeTrackChrome Full support 26Edge Full support 12Firefox Full support YesIE No support NoOpera Full support YesSafari Full support YesWebView Android Full support 37Chrome Android Full support 26Edge Mobile ? Firefox Android Full support YesOpera Android No support NoSafari iOS Full support YesSamsung Internet Android Full support Yes
removetrack eventChrome Full support YesEdge Full support 12Firefox No support NoIE No support NoOpera No support NoSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android No support NoOpera Android No support NoSafari iOS Full support YesSamsung Internet Android Full support Yes
label
Deprecated
Chrome No support ? — 54
Notes
No support ? — 54
Notes
Notes Deprecated in Chrome 45.
Edge ? Firefox ? IE No support NoOpera No support NoSafari ? WebView Android No support ? — 54
Notes
No support ? — 54
Notes
Notes Deprecated in Chrome 45.
Chrome Android No support ? — 54
Notes
No support ? — 54
Notes
Notes Deprecated in Chrome 45.
Edge Mobile ? Firefox Android ? Opera Android No support NoSafari iOS ? Samsung Internet Android Full support Yes
stop
Deprecated
Chrome No support ? — 47Edge Full support 13Firefox ? IE No support NoOpera No support NoSafari ? WebView Android No support ? — 47Chrome Android No support ? — 47Edge Mobile ? Firefox Android ? Opera Android No support NoSafari iOS ? Samsung Internet Android No support No

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.
Deprecated. Not for use in new websites.
Deprecated. Not for use in new websites.
See implementation notes.
See implementation notes.

See also