This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2017.
The MediaStream interface of the Media Capture and Streams API 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 functions such as MediaDevices.getUserMedia(), MediaDevices.getDisplayMedia(), or HTMLCanvasElement.captureStream() and HTMLMediaElement.captureStream().
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).
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.id Read only
A string containing a 36-character universally unique identifier (UUID) for the object.
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.
addtrackFired when a new MediaStreamTrack object is added.
removetrackFired when a MediaStreamTrack object has been removed.
active Non-standard
Fired when the MediaStream is activated.
inactive Non-standard
Fired when the MediaStream is inactivated.
| Specification |
|---|
| Media Capture and Streams> # mediastream> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
MediaStream |
5521 | 1279 | 44 | 4215 | 11 | 5525 | 42 | 4214 | 11 | 6.01.5 | 554.4 | 11 |
MediaStream |
5521 | 1279 | 15 | 4215 | 11 | 5525 | 15 | 4214 | 11 | 6.01.5 | 554.4 | 11 |
active |
42 | 12 | 52 | 29 | 11 | 42 | 52 | 29 | 11 | 4.0 | 42 | 11 |
active_event |
42 | 12 | No | 29 | No | 42 | No | 29 | No | 4.0 | 42 | No |
addTrack |
26 | 12 | 44 | 15 | 11 | 26 | 44 | 14 | 11 | 1.5 | 37 | 11 |
addtrack_event |
26 | 12 | 50 | 15 | 11 | 26 | 50 | 14 | 11 | 1.5 | 4.4 | 11 |
clone |
35 | 12 | 48 | 22 | 11 | 35 | 48 | 22 | 11 | 3.0 | 37 | 11 |
getAudioTracks |
26 | 12 | 22Before Firefox 64, this method returned an array ofAudioStreamTrack objects. However, MediaStreamTrack has now subsumed that interface's functionality. |
15 | 11 | 26 | 22Before Firefox for Android 64, this method returned an array ofAudioStreamTrack objects. However, MediaStreamTrack has now subsumed that interface's functionality. |
14 | 11 | 1.5 | 37 | 11 |
getTrackById |
26 | 12 | 49 | 15 | 11 | 26 | 49 | 14 | 11 | 1.5 | 37 | 11 |
getTracks |
38 | 12 | 34 | 25 | 11 | 38 | 34 | 25 | 11 | 3.0 | 38 | 11 |
getVideoTracks |
26 | 12 | 22Before Firefox 64, this method returned an array ofVideoStreamTrack objects. However, MediaStreamTrack has now subsumed that interface's functionality. |
15 | 11 | 26 | 22Before Firefox for Android 64, this method returned an array ofVideoStreamTrack objects. However, MediaStreamTrack has now subsumed that interface's functionality. |
14 | 11 | 1.5 | 37 | 11 |
id |
26 | 12 | 41 | 15 | 11 | 26 | 41 | 14 | 11 | 1.5 | 4.4 | 11 |
inactive_event |
42 | 12 | No | 29 | No | 42 | No | 29 | No | 4.0 | 42 | No |
removeTrack |
26 | 12 | 44 | 15 | 11 | 26 | 44 | 14 | 11 | 1.5 | 37 | 11 |
removetrack_event |
26 | 12 | 7259–72Before Firefox 72, the event handler was exposed but had no effect. |
15 | 11 | 26 | 7959–79Before Firefox for Android 79, the event handler was exposed but had no effect. |
14 | 11 | 1.5 | 4.4 | 11 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/MediaStream