MDN wants to learn about developers like you: https://qsurvey.mozilla.com/s3/MDN-dev-survey

MediaStreamAudioSourceNode.MediaStreamAudioSourceNode()

MediaStreamAudioSourceNode()构造器创建一个新的 MediaStreamAudioSourceNode对象实例。

语法

var myAudioSource = new MediaStreamAudioSourceNode(context, options);

参数

context
一个用来使用node的音频环境AudioContext
options
MediaStreamAudioSourceOptions,一个map对象,定义MediaStreamAudioSourceNode的属性:
  • mediaStream: 需要使用的音频流

示例

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

// getUserMedia block - grab stream 获取音频流
// put it into a  把音频流放入 MediaStreamAudioSourceNode
if (navigator.mediaDevices.getUserMedia) {
   console.log('new getUserMedia supported.');
   navigator.mediaDevices.getUserMedia (
      // constraints: audio and video for this app
      {
         audio: true,
         video: false
     }).then(function(stream) {

       // Create a MediaStreamAudioSourceNode
       var options = {
         mediaStream : stream
       }

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

规范

Specification Status Comment
Web Audio API
MediaStreamAudioSourceNode
Working Draft  

兼容性

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support (Yes)
 
未实现 未实现

(Yes)

未实现
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile Chrome for Android
Basic support 未实现 未实现 未实现 未实现 未实现 (Yes)

文档标签和贡献者

 此页面的贡献者: maicss
 最后编辑者: maicss,