Web/API/MediaStream

From Get docs


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.
active
Fired when the MediaStream is activated.
inactive
Fired when the MediaStream is inactivated.

Specifications

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

Browser compatibility

Update compatibility data on GitHub

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
MediaStream

Chrome Full support 55


Full support 55


Full support 21

Prefixed'

Prefixed' Implemented with the vendor prefix: webkit

Edge

Full support 12

Firefox

Full support 15

IE

No support No

Opera Full support 42


Full support 42


Full support 15

Prefixed'

Prefixed' Implemented with the vendor prefix: webkit

Safari

Full support 11

WebView Android Full support 55


Full support 55


Full support ≤37

Prefixed'

Prefixed' Implemented with the vendor prefix: webkit

Chrome Android Full support 55


Full support 55


Full support 25

Prefixed'

Prefixed' Implemented with the vendor prefix: webkit

Firefox Android

Full support 15

Opera Android Full support 42


Full support 42


Full support 14

Prefixed'

Prefixed' Implemented with the vendor prefix: webkit

Safari iOS

Full support 11

Samsung Internet Android Full support 6.0


Full support 6.0


Full support 1.5

Prefixed'

Prefixed' Implemented with the vendor prefix: webkit

MediaStream() constructor Chrome

Full support 21

Edge

Full support ≤18

Firefox

Full support 44

IE

No support No

Opera

Full support 42

Safari

No support No

WebView Android

Full support 37

Chrome Android

Full support 25

Firefox Android

Full support 42

Opera Android

No support No

Safari iOS

No support No

Samsung Internet Android

Full support 6.0

active Chrome

Full support 45

Edge

Full support 12

Firefox

Full support 52

IE

No support No

Opera

No support No

Safari

Full support Yes

WebView Android

Full support 45

Chrome Android

Full support 45

Firefox Android

Full support 52

Opera Android

No support No

Safari iOS

Full support Yes

Samsung Internet Android

Full support 5.0

active event Chrome

Full support 45

Edge

Full support ≤79

Firefox

?

IE

No support No

Opera

?

Safari

?

WebView Android

Full support 45

Chrome Android

Full support 45

Firefox Android

?

Opera Android

No support No

Safari iOS

?

Samsung Internet Android

Full support 5.0

addTrack Chrome

Full support 26

Edge

Full support 12

Firefox

Full support 44

IE

No support No

Opera

No support No

Safari

Full support Yes

WebView Android

Full support 37

Chrome Android

Full support 26

Firefox Android

No support No

Opera Android

No support No

Safari iOS

Full support Yes

Samsung Internet Android

Full support 1.5

addtrack event Chrome

Full support Yes

Edge

Full support 12

Firefox

Full support 50

IE

No support No

Opera

No support No

Safari

Full support Yes

WebView Android

Full support Yes

Chrome Android

Full support Yes

Firefox Android

Full support 50

Opera Android

No support No

Safari iOS

Full support Yes

Samsung Internet Android

Full support Yes

clone Chrome

Full support 45

Edge

Full support 12

Firefox

Full support 48

IE

No support No

Opera

No support No

Safari

Full support Yes

WebView Android

Full support 45

Chrome Android

Full support 45

Firefox Android

Full support 48

Opera Android

No support No

Safari iOS

Full support Yes

Samsung Internet Android

Full support 5.0

ended

Deprecated'

Chrome No support ? — 54

Notes'

No support ? — 54

Notes'

Notes' Deprecated in Chrome 52.

Edge

?

Firefox

No support No

IE

No support No

Opera

No support ? — 39

Safari

?

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 No

Opera Android

No support ? — 41

Safari iOS

?

Samsung Internet Android No support ? — 6.0

Notes'

No support ? — 6.0

Notes'

Notes' Deprecated in Samsung Internet 6.0.

getAudioTracks Chrome

Full support 26

Edge

Full support 12

Firefox 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 No

Opera

Full support Yes

Safari

Full support Yes

WebView Android

Full support 37

Chrome Android

Full support 26

Firefox 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 No

Safari iOS

Full support Yes

Samsung Internet Android

Full support 1.5

getTrackById Chrome

Full support 26

Edge

Full support 12

Firefox

Full support 49

IE

No support No

Opera

No support No

Safari

Full support Yes

WebView Android

Full support 37

Chrome Android

Full support 26

Firefox Android

Full support 49

Opera Android

No support No

Safari iOS

Full support Yes

Samsung Internet Android

Full support 1.5

getTracks

Experimental'

Chrome

Full support 45

Edge

Full support 12

Firefox

Full support Yes

IE

No support No

Opera

Full support Yes

Safari

Full support Yes

WebView Android

Full support 45

Chrome Android

Full support 45

Firefox Android

Full support Yes

Opera Android

No support No

Safari iOS

Full support Yes

Samsung Internet Android

Full support 5.0

getVideoTracks

Experimental'

Chrome

Full support 26

Edge

Full support 12

Firefox 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 No

Opera

Full support Yes

Safari

Full support Yes

WebView Android

Full support 37

Chrome Android

Full support 26

Firefox 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 No

Safari iOS

Full support Yes

Samsung Internet Android

Full support 1.5

id Chrome

No support ? — 54

Edge

No support 12 — 79

Firefox

Full support 41

IE

No support No

Opera

No support ? — 39

Safari

Full support Yes

WebView Android

No support ? — 54

Chrome Android

No support ? — 54

Firefox Android

Full support 41

Opera Android

No support ? — 41

Safari iOS

Full support Yes

Samsung Internet Android

No support ? — 6.0

inactive event Chrome

Full support 45

Edge

Full support ≤79

Firefox

?

IE

No support No

Opera

?

Safari

?

WebView Android

Full support 45

Chrome Android

Full support 45

Firefox Android

?

Opera Android

No support No

Safari iOS

?

Samsung Internet Android

Full support 5.0

label

Deprecated'

Chrome No support ? — 54

Notes'

No support ? — 54

Notes'

Notes' Deprecated in Chrome 45.

Edge

?

Firefox

?

IE

No support No

Opera

No support No

Safari

?

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 No

Safari iOS

?

Samsung Internet Android No support ? — 6.0

Notes'

No support ? — 6.0

Notes'

Notes' Deprecated in Samsung Internet 5.0.

onactive Chrome

Full support 45

Edge

Full support ≤79

Firefox

?

IE

No support No

Opera

?

Safari

?

WebView Android

Full support 45

Chrome Android

Full support 45

Firefox Android

?

Opera Android

No support No

Safari iOS

?

Samsung Internet Android

Full support 5.0

onaddtrack Chrome

Full support 26

Edge

Full support 12

Firefox

Full support 50

IE

No support No

Opera

No support No

Safari

Full support Yes

WebView Android

Full support 37

Chrome Android

Full support 26

Firefox Android

Full support 50

Opera Android

No support No

Safari iOS

Full support Yes

Samsung Internet Android

Full support 1.5

oninactive Chrome

Full support 45

Edge

Full support ≤79

Firefox

?

IE

No support No

Opera

?

Safari

?

WebView Android

Full support 45

Chrome Android

Full support 45

Firefox Android

?

Opera Android

No support No

Safari iOS

?

Samsung Internet Android

Full support 5.0

onremovetrack Chrome

Full support 26

Edge

Full support 12

Firefox

No support No

IE

No support No

Opera

No support No

Safari

Full support Yes

WebView Android

Full support 37

Chrome Android

Full support 26

Firefox Android

No support No

Opera Android

No support No

Safari iOS

Full support Yes

Samsung Internet Android

Full support 1.5

removeTrack Chrome

Full support 26

Edge

Full support 12

Firefox

Full support Yes

IE

No support No

Opera

Full support Yes

Safari

Full support Yes

WebView Android

Full support 37

Chrome Android

Full support 26

Firefox Android

Full support Yes

Opera Android

No support No

Safari iOS

Full support Yes

Samsung Internet Android

Full support 1.5

removetrack event Chrome

Full support Yes

Edge

Full support 12

Firefox

No support No

IE

No support No

Opera

No support No

Safari

Full support Yes

WebView Android

Full support Yes

Chrome Android

Full support Yes

Firefox Android

No support No

Opera Android

No support No

Safari iOS

Full support Yes

Samsung Internet Android

Full support Yes

stop

Deprecated'

Chrome

No support ? — 47

Edge

No support 13 — 79

Firefox

?

IE

No support No

Opera

No support No

Safari

?

WebView Android

No support ? — 47

Chrome Android

No support ? — 47

Firefox Android

?

Opera Android

No support No

Safari iOS

?

Samsung Internet Android

No support ? — 5.0

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.
Requires a vendor prefix or different name for use.'
Requires a vendor prefix or different name for use.


See also