W3cubDocs

/Web APIs

Media Capture and Streams API (Media Stream)

The Media Capture and Streams API, often called the Media Streams API or MediaStream API, is an API related to WebRTC which provides support for streaming audio and video data.

It provides the interfaces and methods for working with the streams and their constituent tracks, the constraints associated with data formats, the success and error callbacks when using the data asynchronously, and the events that are fired during the process.

Concepts and usage

The API is based on the manipulation of a MediaStream object representing a flux of audio- or video-related data. See an example in Get the video.

A MediaStream consists of zero or more MediaStreamTrack objects, representing various audio or video tracks. Each MediaStreamTrack may have one or more channels. The channel represents the smallest unit of a media stream, such as an audio signal associated with a given speaker, like left or right in a stereo audio track.

MediaStream objects have a single input and a single output. A MediaStream object generated by getUserMedia() is called local, and has as its source input one of the user's cameras or microphones. A non-local MediaStream may be representing a media element, like <video> or <audio>, a stream originating over the network, and obtained via the WebRTC RTCPeerConnection API, or a stream created using the Web Audio API MediaStreamAudioDestinationNode.

The output of the MediaStream object is linked to a consumer. It can be a media element, like <audio> or <video>, the WebRTC RTCPeerConnection API or a Web Audio API MediaStreamAudioSourceNode.

Interfaces

In these reference articles, you'll find the fundamental information you'll need to know about each of the interfaces that make up the Media Capture and Streams API.

Early versions of the Media Capture and Streams API specification included separate AudioStreamTrack and VideoStreamTrack interfaces—each based upon MediaStreamTrack—which represented streams of those types. These no longer exist, and you should update any existing code to instead use MediaStreamTrack directly.

Events

Guides and tutorials

The articles below provide additional guidance and how-to information that will help you learn to use the API, and how to perform specific tasks that you may wish to handle.

Capabilities, constraints, and settings

This article discusses the twin concepts of constraints and capabilities, as well as media settings, and includes an example we call the Constraint Exerciser. The Constraint Exerciser lets you experiment with the results of different constraint sets being applied to the audio and video tracks coming from the computer's A/V input devices (such as its webcam and microphone).

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
Media_Streams_API
55
21
79
12
15
No
42
15
11
55
≤37
55
25
15
42
14
11
6.0
1.5
MediaStream
55
21
79
12
44
No
42
15
11
55
≤37
55
25
42
42
14
11
6.0
1.5
active
45
12
52
No
No
11
45
45
52
No
11
5.0
active_event
45
12
No
No
32
No
45
45
No
No
No
5.0
addTrack
26
12
44
No
No
11
37
26
No
No
11
1.5
addtrack_event
26
12
50
No
No
11
≤37
26
50
No
11
1.5
clone
45
12
48
No
No
11
45
45
48
No
11
5.0
getAudioTracks
26
12
22
Before Firefox 64, this method returned an array of AudioStreamTrack objects. However, MediaStreamTrack has now subsumed that interface's functionality.
No
15
11
37
26
22
Before Firefox 64, this method returned an array of AudioStreamTrack objects. However, MediaStreamTrack has now subsumed that interface's functionality.
No
11
1.5
getTrackById
26
12
49
No
No
11
37
26
49
No
11
1.5
getTracks
45
12
34
No
32
11
45
45
34
No
11
5.0
getVideoTracks
26
12
22
Before Firefox 64, this method returned an array of VideoStreamTrack objects. However, MediaStreamTrack has now subsumed that interface's functionality.
No
15
11
37
26
22
Before Firefox 64, this method returned an array of VideoStreamTrack objects. However, MediaStreamTrack has now subsumed that interface's functionality.
No
11
1.5
id
26
12
41
No
15
11
≤37
26
41
14
11
1.5
inactive_event
45
12
No
No
32
No
45
45
No
No
No
5.0
removeTrack
26
12
44
No
15
11
37
26
44
No
11
1.5
removetrack_event
26
12
No
No
No
11
≤37
26
No
No
11
1.5
stop
29-47
13-79
No
No
No
No
≤37-47
29-47
No
No
No
2.0-5.0

See also

© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Media_Streams_API