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 media stream.
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 APIMediaStreamAudioDestinationNode.
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.
The Capabilities, constraints, and settings article discusses the concepts of constraints and capabilities, as well as media settings, and includes a Constraint Exerciser that 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).
39Before Firefox 67, related devices are not actually grouped together by groupId.
34
11
47
39Before Firefox 67, related devices are not actually grouped together by groupId.
34
11
5.0
47
kind
47
12
39
34
11
47
39
34
11
5.0
47
label
47
12
39
34
11
47
39
34
11
5.0
47
toJSON
47
18
42
34
11
47
42
34
11
5.0
47
Desktop
Mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on IOS
Samsung Internet
WebView Android
Media_Capture_and_Streams_API
47
12
33
30
11
47
36
30
11
5.0
47
devicechange_event
57
12
52
34
11
No
52
No
11
No
No
enumerateDevices
47
12
116enumerateDevices() enumerates both input and output devices. Previously only input devices were returned.39enumerateDevices() only returns input devices.
34
11
47
116enumerateDevices() enumerates both input and output devices. Previously only input devices were returned.39enumerateDevices() only returns input devices.
34
11
5.0
47
getDisplayMedia
72
7917–79Available as a member of Navigator instead of MediaDevices.
6633–66Since Firefox 33 you can capture screen data using getUserMedia(), with a video constraint called mediaSource. Before 52 it relied on a client-configurable list of allowed sites.
60
13
NoFrom Chrome Android 72 to 88, this method was exposed, but always failed with NotAllowedError. See bug 487935.
NoFrom Firefox Android 66 to 79, this method was exposed, but always failed with NotAllowedError.
NoFrom Opera Android 72 to 88, this method was exposed, but always failed with NotAllowedError. See bug 487935.
No
NoFrom Samsung Internet Android 72 to 88, this method was exposed, but always failed with NotAllowedError. See bug 487935.
NoFrom Chrome Android 72 to 88, this method was exposed, but always failed with NotAllowedError. See bug 487935.
getSupportedConstraints
53
12
44
40
11
52
50
41
11
6.0
53
getUserMedia
53If you need this capability before version 53, refer to navigator.webkitGetUserMedia, a prefixed form of the deprecated navigator.getUserMedia API.
12
36["If you need this capability before version 36, refer to navigator.mozGetUserMedia, a prefixed form of the deprecated navigator.getUserMedia API.", "Before Firefox 55, getUserMedia() incorrectly returns NotSupportedError when the list of constraints specified is empty, or has all constraints set to false. Starting in Firefox 55, this situation now correctly calls the failure handler with a TypeError.", "When using the Firefox-specific video constraint called mediaSource to request display capture, Firefox 66 and later consider values of screen and window to both cause a list of screens and windows to be shown.", "Starting in Firefox 66, getUserMedia() can no longer be used in sandboxed <iframe>s or data URLs entered in the address bar by the user."]
40If you need this capability before version 40, refer to navigator.webkitGetUserMedia, a prefixed form of the deprecated navigator.getUserMedia API.
11
53If you need this capability before version 53, refer to navigator.webkitGetUserMedia, a prefixed form of the deprecated navigator.getUserMedia API.
36["If you need this capability before version 36, refer to navigator.mozGetUserMedia, a prefixed form of the deprecated navigator.getUserMedia API.", "Before Firefox 55, getUserMedia() incorrectly returns NotSupportedError when the list of constraints specified is empty, or has all constraints set to false. Starting in Firefox 55, this situation now correctly calls the failure handler with a TypeError.", "When using the Firefox-specific video constraint called mediaSource to request display capture, Firefox 66 and later consider values of screen and window to both cause a list of screens and windows to be shown.", "Starting in Firefox 66, getUserMedia() can no longer be used in sandboxed <iframe>s or data URLs entered in the address bar by the user."]
41If you need this capability before version 41, refer to navigator.webkitGetUserMedia, a prefixed form of the deprecated navigator.getUserMedia API.
11
6.0
53
selectAudioOutput
No
No
116
No
No
No
No
No
No
No
No
setCaptureHandleConfig
102
102
No
88
No
No
No
No
No
No
No
Desktop
Mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on IOS
Samsung Internet
WebView Android
Media_Capture_and_Streams_API
26
12
22
15
11
26
22
14
11
1.5
4.4
applyConstraints
59
12
43
46
11
59
43
43
11
7.0
59
capturehandlechange_event
102
102
No
88
No
No
No
No
No
No
No
clone
35
12
48
22
11
35
48
22
11
3.0
37
contentHint
70
79
No
57
12.1
70
No
49
12.2
10.0
70
enabled
26
12
24
15
11
26
24
14
11
1.5
4.4
ended_event
26
12
50
15
11
26
50
14
11
1.5
4.4
getCapabilities
59
12
No
46
11
59
No
43
11
7.0
59
getCaptureHandle
102
102
No
88
No
No
No
No
No
No
No
getConstraints
53
12
50
40
11
52
50
41
11
6.0
53
getSettings
59
12
50
46
11
59
50
43
11
7.0
59
id
26
12
22
15
11
26
22
14
11
1.5
4.4
kind
26
12
22
15
11
26
22
14
11
1.5
4.4
label
26
12
22
15
11
26
22
14
11
1.5
4.4
mute_event
26
12
59
15
11
26
59
14
11
1.5
4.4
muted
38
12
59Does not currently track the microphone's muted state from the operating system, see bug 1739163.
25
11
38
59Does not currently track the microphone's muted state from the operating system, see bug 1739163.
25
11
3.0
38
readyState
26
12
50
15
11
26
50
14
11
1.5
4.4
stop
32
12
34
19
11
32
34
19
11
2.0
4.4.3
unmute_event
26
12
59
15
11
26
59
14
11
1.5
4.4
Desktop
Mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on IOS
Samsung Internet
WebView Android
MediaStream
5521
1279
44
4215
11
5525
42
4214
11
6.01.5
554.4
Media_Capture_and_Streams_API
5521
1279
15
4215
11
5525
15
4214
11
6.01.5
554.4
active
42
12
52
29
11
42
52
29
11
4.0
42
active_event
42
12
No
29
No
42
No
29
No
4.0
42
addTrack
26
12
44
15
11
26
44
14
11
1.5
37
addtrack_event
26
12
50
15
11
26
50
14
11
1.5
4.4
clone
35
12
48
22
11
35
48
22
11
3.0
37
getAudioTracks
26
12
22Before Firefox 64, this method returned an array of AudioStreamTrack objects. However, MediaStreamTrack has now subsumed that interface's functionality.
15
11
26
22Before Firefox 64, this method returned an array of AudioStreamTrack objects. However, MediaStreamTrack has now subsumed that interface's functionality.
14
11
1.5
37
getTrackById
26
12
49
15
11
26
49
14
11
1.5
37
getTracks
38
12
34
25
11
38
34
25
11
3.0
38
getVideoTracks
26
12
22Before Firefox 64, this method returned an array of VideoStreamTrack objects. However, MediaStreamTrack has now subsumed that interface's functionality.
15
11
26
22Before Firefox 64, this method returned an array of VideoStreamTrack objects. However, MediaStreamTrack has now subsumed that interface's functionality.
14
11
1.5
37
id
26
12
41
15
11
26
41
14
11
1.5
4.4
inactive_event
42
12
No
29
No
42
No
29
No
4.0
42
removeTrack
26
12
44
15
11
26
44
14
11
1.5
37
removetrack_event
26
12
7259–72Before Firefox 72, the event handler was exposed but had no effect.
15
11
26
7959–79Before Firefox 72, the event handler was exposed but had no effect.