MediaStream

You’re reading the English version of this content since no translation exists yet for this locale. Help us translate this article!

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.

Events

addtrack
Fired when a new MediaStreamTrack object is added.
Also available via the onaddtrack property.
removetrack
Fired when a MediaStreamTrack object has been removed.
Also available via the onremovetrack property.

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 AndroidFirefox 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 18Firefox 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 25Firefox 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 45Firefox Android Full support 52Opera Android No support NoSafari iOS Full support YesSamsung Internet Android Full support Yes
active eventChrome Full support 45Edge ? Firefox ? IE No support NoOpera ? Safari ? WebView Android Full support 45Chrome Android Full support 45Firefox Android ? Opera Android No support NoSafari iOS ? Samsung Internet Android ?
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 26Firefox Android No support NoOpera Android No support NoSafari iOS Full support YesSamsung Internet Android Full support Yes
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 YesFirefox Android Full support 50Opera 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 45Firefox Android Full support 48Opera 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.
Firefox Android No support NoOpera Android No support ? — 41Safari iOS ? Samsung 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 26Firefox 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 26Firefox 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 45Firefox 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 26Firefox 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
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 ? — 54Firefox Android Full support 41Opera Android No support ? — 41Safari iOS Full support YesSamsung Internet Android Full support Yes
inactive eventChrome Full support 45Edge ? Firefox ? IE No support NoOpera ? Safari ? WebView Android Full support 45Chrome Android Full support 45Firefox Android ? Opera Android No support NoSafari iOS ? Samsung Internet Android ?
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.
Firefox Android ? Opera Android No support NoSafari iOS ? Samsung Internet Android Full support Yes
onactiveChrome Full support 45Edge ? Firefox ? IE No support NoOpera ? Safari ? WebView Android Full support 45Chrome Android Full support 45Firefox Android ? Opera Android No support NoSafari 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 26Firefox Android Full support 50Opera Android No support NoSafari iOS Full support YesSamsung Internet Android Full support Yes
oninactiveChrome Full support 45Edge ? Firefox ? IE No support NoOpera ? Safari ? WebView Android Full support 45Chrome Android Full support 45Firefox Android ? Opera Android No support NoSafari 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 26Firefox Android No support NoOpera 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 26Firefox 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 YesFirefox Android No support NoOpera Android No support NoSafari iOS Full support YesSamsung 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 ? — 47Firefox 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