The MediaStream interface represents a stream of media content. A stream consists of several tracks such as video or audio tracks. Each track is specified as an instance of MediaStreamTrack.You can obtain a MediaStream object either by using the constructor or by calling MediaDevices.getUserMedia().

Some user agents subclass this interface to provide more precise information or functionality, like in CanvasCaptureMediaStream.

Constructor

MediaStream()
Creates and returns a new MediaStream object. You can create an empty stream, a stream which is based upon an existing stream, or a stream that contains a specified list of tracks (specified as an array of MediaStreamTrack objects).

Properties

This interface inherits properties from its parent, EventTarget.

MediaStream.active Read only
A Boolean value that returns true if the MediaStream is active, or false otherwise.
MediaStream.ended Read only  
A Boolean value set to true if the end of the stream has been reached. This has been removed from the specification; you should instead check the value of MediaStreamTrack.readyState to see if its value is "ended" for the track or tracks you want to ensure have finished playing.
MediaStream.id Read only
A DOMString containing 36 characters denoting a universally unique identifier (UUID) for the object.

Event handlers

MediaStream.onaddtrack
An EventHandler containing the action to perform when an addtrack event is fired when a new MediaStreamTrack object is added.
MediaStream.onremovetrack
An EventHandler containing the action to perform when a removetrack event is fired when a  MediaStreamTrack object is removed from it.

Methods

This interface inherits methods from its parent, EventTarget.

MediaStream.addTrack()
Stores a copy of the MediaStreamTrack given as argument. If the track has already been added to the MediaStream object, nothing happens.
MediaStream.clone()
Returns a clone of the MediaStream object. The clone will, however, have a unique value for id.
MediaStream.getAudioTracks()
Returns a list of the MediaStreamTrack objects stored in the MediaStream object that have their kind attribute set to "audio". The order is not defined, and may not only vary from one browser to another, but also from one call to another.
MediaStream.getTrackById()
Returns the track whose ID corresponds to the one given in parameters, trackid. If no parameter is given, or if no track with that ID does exist, it returns null. If several tracks have the same ID, it returns the first one.
MediaStream.getTracks()
Returns a list of all MediaStreamTrack objects stored in the MediaStream object, regardless of the value of the kind attribute. The order is not defined, and may not only vary from one browser to another, but also from one call to another.
MediaStream.getVideoTracks()
Returns a list of the MediaStreamTrack objects stored in the MediaStream object that have their kind attribute set to "video". The order is not defined, and may not only vary from one browser to another, but also from one call to another.
MediaStream.removeTrack()
Removes the MediaStreamTrack given as argument. If the track is not part of the MediaStream object, nothing happens.

Specifications

Specification Status Comment
Media Capture and Streams
The definition of 'MediaStream' in that specification.
Candidate Recommendation  

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
Basic supportChrome Full support YesEdge Full support YesFirefox Full support 15IE No support NoOpera No support NoSafari ? WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 15Opera Android No support NoSafari iOS ? Samsung Internet Android Full support Yes
MediaStreamChrome Full support 55Edge Full support YesFirefox Full support 44IE No support NoOpera Full support 42Safari No support NoWebView Android Full support 55Chrome Android Full support 55Edge Mobile Full support YesFirefox Android Full support 42Opera Android ? Safari iOS No support NoSamsung Internet Android Full support 6.0
activeChrome Full support YesEdge Full support 12Firefox Full support 52IE ? Opera ? Safari ? WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 52Opera Android ? Safari iOS ? Samsung 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 ? Opera 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 ? — 39Safari iOS ? Samsung Internet Android Full support Yes
idChrome No support ? — 54Edge Full support 12Firefox Full support 41IE ? Opera No support ? — 39Safari ? WebView Android No support ? — 54Chrome Android No support ? — 54Edge Mobile Full support YesFirefox Android Full support 41Opera Android No support ? — 39Safari iOS ? Samsung Internet Android Full support Yes
onaddtrackChrome Full support YesEdge Full support 12Firefox Full support 50IE ? Opera ? Safari ? WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 50Opera Android ? Safari iOS ? Samsung Internet Android Full support Yes
onremovetrackChrome Full support YesEdge Full support 12Firefox No support NoIE ? Opera ? Safari ? WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android No support NoOpera Android ? Safari iOS ? Samsung Internet Android Full support Yes
addTrackChrome Full support YesEdge Full support 12Firefox Full support 44IE ? Opera ? Safari ? WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android No support NoOpera Android ? Safari iOS ? Samsung Internet Android Full support Yes
cloneChrome Full support YesEdge Full support 12Firefox Full support 48IE ? Opera ? Safari ? WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 48Opera Android ? Safari iOS ? Samsung Internet Android Full support Yes
getAudioTracksChrome Full support YesEdge 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 ? Opera Full support YesSafari ? WebView Android Full support YesChrome Android Full support YesEdge 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 ? Safari iOS ? Samsung Internet Android Full support Yes
getTrackByIdChrome Full support YesEdge Full support 12Firefox Full support 49IE No support NoOpera ? Safari ? WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 49Opera Android ? Safari iOS ? Samsung Internet Android Full support Yes
getTracks
Experimental
Chrome Full support YesEdge Full support 12Firefox ? IE ? Opera Full support YesSafari ? WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android ? Opera Android ? Safari iOS ? Samsung Internet Android Full support Yes
getVideoTracks
Experimental
Chrome Full support YesEdge 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 ? Opera Full support YesSafari ? WebView Android Full support YesChrome Android Full support YesEdge 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 ? Safari iOS ? Samsung Internet Android Full support Yes
removeTrackChrome Full support YesEdge Full support 12Firefox ? IE ? Opera Full support YesSafari ? WebView Android Full support YesChrome Android Full support YesEdge Mobile ? Firefox Android ? Opera Android ? Safari iOS ? Samsung 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 NoEdge Full support 13Firefox ? IE No support NoOpera No support NoSafari ? WebView Android No support NoChrome Android No support NoEdge 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

Document Tags and Contributors

Last updated by: sideshowbarker,