MediaStreamAudioSourceNode.MediaStreamAudioSourceNode()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2021.
**MediaStreamAudioSourceNode()
**构造器创建一个新的 MediaStreamAudioSourceNode
对象实例。
语法
js
var myAudioSource = new MediaStreamAudioSourceNode(context, options);
参数
- context
-
一个用来使用 node 的音频环境
AudioContext
。 - options
-
MediaStreamAudioSourceOptions
,一个 map 对象,定义MediaStreamAudioSourceNode
的属性:mediaStream
: 需要使用的音频流
示例
js
// 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 |
---|
Web Audio API # dom-mediastreamaudiosourcenode-mediastreamaudiosourcenode |
浏览器兼容性
BCD tables only load in the browser