MediaStreamAudioSourceNode

The MediaStreamAudioSourceNode interface is a type of AudioNode which operates as an audio source whose media is received from a MediaStream obtained using the WebRTC or Media Capture and Streams APIs.

This media could be from a microphone (through getUserMedia()) or from a remote peer on a WebRTC call (using the RTCPeerConnection's audio tracks).

A MediaStreamAudioSourceNode has no inputs and exactly one output, and is created using the AudioContext.createMediaStreamSource() method.

The MediaStreamAudioSourceNode takes the audio from the first MediaStreamTrack whose kind attribute's value is audio. See Track ordering for more information about the order of tracks.

The number of channels output by the node matches the number of tracks found in the selected audio track.

Number of inputs 0
Number of outputs 1
Channel count defined by the first audio MediaStreamTrack passed to the AudioContext.createMediaStreamSource() method that created it.

Constructor

new MediaStreamAudioSourceNode()

Creates a new MediaStreamAudioSourceNode object instance with the specified options.

Properties

In addition to the following properties, MediaStreamAudioSourceNode inherits the properties of its parent, AudioNode.

mediaStream Read only

The MediaStream used when constructing this MediaStreamAudioSourceNode.

Methods

Inherits methods from its parent, AudioNode.

Exceptions

InvalidStateError

The stream specified by the mediaStream parameter does not contain any audio tracks.

Usage notes

Track ordering

For the purposes of the MediaStreamTrackAudioSourceNode interface, the order of the audio tracks on the stream is determined by taking the tracks whose kind is audio, then sorting the tracks by their id property's values, in Unicode code point order (essentially, in alphabetical or lexicographical order, for IDs which are simple alphanumeric strings).

The first track, then, is the track whose id comes first when the tracks' IDs are all sorted by Unicode code point.

However, it's important to note that the rule establishing this ordering was added long after this interface was first introduced into the Web Audio API. As such, you can't easily rely on the order matching between any two browsers or browser versions.

The MediaStreamTrackAudioSourceNode interface is similar to MediaStreamAudioSourceNode, but avoids this problem by letting you specify which track you want to use.

Example

See AudioContext.createMediaStreamSource() for example code that uses this object.

Specifications

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
MediaStreamAudioSourceNode
23
12
25
No
15
11
≤37
Yes
25
14
11
Yes
MediaStreamAudioSourceNode
55
Before Chrome 59, the default values were not supported.
79
53
No
42
14.1
55
Before Chrome 59, the default values were not supported.
55
Before Chrome 59, the default values were not supported.
53
42
14.5
6.0
Before Samsung Internet 7.0, the default values were not supported.
mediaStream
23
≤79
70
No
Yes
11
≤37
Yes
No
Yes
11
Yes

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/MediaStreamAudioSourceNode