MediaStreamAudioSourceOptions.mediaStream

The MediaStreamAudioSourceOptions dictionary's mediaStream property must specify the MediaStream from which to retrieve audio data when instantiating a MediaStreamAudioSourceNode using the MediaStreamAudioSourceNode() constructor.

Syntax

mediaStreamAudioSourceOptions = {
  mediaStream: audioSourceStream;
}

mediaStreamAudioSourceOptions.mediaStream = audioSourceStream;

Value

A MediaStream representing the stream from which to use a MediaStreamTrack as the source of audio for the node.

Example

This example uses getUserMedia() to obtain access to the user's camera, then creates a new MediaStreamAudioSourceNode from its MediaStream.

// define variables
var audioCtx = new (window.AudioContext || window.webkitAudioContext)();

// getUserMedia block - grab stream
// put it into a MediaStreamAudioSourceNode
if (navigator.mediaDevices.getUserMedia) {
   navigator.mediaDevices.getUserMedia (
      // constraints: audio and video for this app
      {
         audio: true,
         video: false
      }).then(function(stream) {
        var options = {
          mediaStream : stream
        }

        var source = new MediaStreamAudioSourceNode(audioCtx, options);
        source.connect(audioCtx.destination);
      }).catch(function(err) {
       console.log('The following gUM error occurred: ' + err);
      });
} else {
  console.log('new getUserMedia not supported on your browser!');
}

Specifications

Specification
Web Audio API
# dom-mediastreamaudiosourceoptions-mediastream

Browser compatibility

BCD tables only load in the browser