The MediaStreaminterface represents a stream of media content. A stream consists of several trackssuch 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.
MediaStream()MediaStreamTrack objects).This interface inherits properties from its parent, EventTarget.
MediaStream.active Read only
true if the MediaStream is active, or false otherwise.MediaStream.ended Read only
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
DOMString containing 36 characters denoting a universally unique identifier (UUID) for the object.MediaStream.onaddtrackEventHandler containing the action to perform when an addtrack event is fired when a new MediaStreamTrack object is added.MediaStream.onremovetrackEventHandler containing the action to perform when a removetrack event is fired when a MediaStreamTrack object is removed from it.This interface inherits methods from its parent, EventTarget.
MediaStream.addTrack()MediaStreamTrack given as argument. If the track has already been added to the MediaStream object, nothing happens.MediaStream.clone()MediaStream object. The clone will, however, have a unique value for id.MediaStream.getAudioTracks()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()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()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()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()MediaStreamTrack given as argument. If the track is not part of the MediaStream object, nothing happens.| Specification | Status | Comment |
|---|---|---|
| Media Capture and Streams The definition of 'MediaStream' in that specification. | Candidate Recommendation |
| 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 |
MediaStreamTrack
© 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/MediaStream