MediaStreamAudioDestinationNode
interface represents an audio destination consisting of a
WebRTC
MediaStream
采用单
AudioMediaStreamTrack
, which can be used in a similar way to a
MediaStream
obtained from
Navigator.getUserMedia()
.
It is an
AudioNode
that acts as an audio destination, created using the
AudioContext.createMediaStreamDestination()
方法。
| 输入数 |
1
|
|---|---|
| 输出数 |
0
|
| 通道计数 |
2
|
| 通道计数模式 |
"explicit"
|
| Channel count interpretation |
"speakers"
|
MediaStreamAudioDestinationNode.MediaStreamAudioDestinationNode()
MediaStreamAudioDestinationNode
对象实例。
继承的特性来自其父级,
AudioNode
.
MediaStreamAudioDestinationNode.stream
MediaStream
containing a single
MediaStreamTrack
whose
kind
is
audio
and with the same number of channels as the node. You can use this property to get a stream out of the audio graph and feed it into another construct, such as a
Media Recorder
.
继承方法来自其父级
AudioNode
.
In the following simple example, we create a
MediaStreamAudioDestinationNode
,
OscillatorNode
和
MediaRecorder
(the example will therefore only work in Firefox and Chrome at this time.) The
MediaRecorder
is set up to record information from the
MediaStreamDestinationNode
.
When the button is clicked, the oscillator starts, and the
MediaRecorder
is started. When the button is stopped, the oscillator and
MediaRecorder
both stop. Stopping the
MediaRecorder
causes the
dataavailable
event to fire, and the event data is pushed into the
chunks
array. After that, the
stop
event fires, a new
blob
is made of type opus — which contains the data in the
chunks
array, and a new window (tab) is then opened that points to a URL created from the blob.
From here, you can play and save the opus file.
<!DOCTYPE html>
<html>
<head>
<title>createMediaStreamDestination() demo</title>
</head>
<body>
<h1>createMediaStreamDestination() demo</h1>
<p>Encoding a pure sine wave to an Opus file </p>
<button>Make sine wave</button>
<audio controls></audio>
<script>
var b = document.querySelector("button");
var clicked = false;
var chunks = [];
var ac = new AudioContext();
var osc = ac.createOscillator();
var dest = ac.createMediaStreamDestination();
var mediaRecorder = new MediaRecorder(dest.stream);
osc.connect(dest);
b.addEventListener("click", function(e) {
if (!clicked) {
mediaRecorder.start();
osc.start(0);
e.target.innerHTML = "Stop recording";
clicked = true;
} else {
mediaRecorder.stop();
osc.stop(0);
e.target.disabled = true;
}
});
mediaRecorder.ondataavailable = function(evt) {
// push each chunk (blobs) in an array
chunks.push(evt.data);
};
mediaRecorder.onstop = function(evt) {
// Make blob out of our blobs, and open it.
var blob = new Blob(chunks, { 'type' : 'audio/ogg; codecs=opus' });
document.querySelector("audio").src = URL.createObjectURL(blob);
};
</script>
</body>
</html>
注意 : You can view this example live ,或 study the source code , on Github.
| 规范 | 状态 | 注释 |
|---|---|---|
|
Web 音频 API
The definition of 'MediaStreamAudioDestinationNode' in that specification. |
工作草案 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
MediaStreamAudioDestinationNode
|
Chrome 14 | Edge ≤18 | Firefox 25 | IE 不支持 No | Opera 15 | Safari 6 | WebView Android Yes | Chrome Android 18 | Firefox Android 26 | Opera Android 14 | Safari iOS Yes | Samsung Internet Android 1.0 |
MediaStreamAudioDestinationNode()
构造函数
|
Chrome 55 | Edge ≤79 | Firefox 53 | IE 不支持 No | Opera 42 | Safari ? |
WebView Android
55
注意事项
|
Chrome Android
55
注意事项
|
Firefox Android 53 | Opera Android 42 | Safari iOS ? |
Samsung Internet Android
6.0
注意事项
|
stream
|
Chrome 14 | Edge ≤18 | Firefox 25 | IE 不支持 No | Opera 15 | Safari 6 | WebView Android Yes | Chrome Android 18 | Firefox Android 26 | Opera Android 14 | Safari iOS Yes | Samsung Internet Android 1.0 |
完整支持
不支持
兼容性未知
见实现注意事项。
MediaStreamAudioDestinationNode
AnalyserNode
AudioBuffer
AudioBufferSourceNode
AudioContext
AudioContextOptions
AudioDestinationNode
AudioListener
AudioNode
AudioNodeOptions
AudioParam
AudioProcessingEvent
AudioScheduledSourceNode
AudioWorklet
AudioWorkletGlobalScope
AudioWorkletNode
AudioWorkletProcessor
BaseAudioContext
BiquadFilterNode
ChannelMergerNode
ChannelSplitterNode
ConstantSourceNode
ConvolverNode
DelayNode
DynamicsCompressorNode
GainNode
IIRFilterNode
MediaElementAudioSourceNode
MediaStreamAudioSourceNode
OfflineAudioCompletionEvent
OfflineAudioContext
OscillatorNode
PannerNode
PeriodicWave
StereoPannerNode
WaveShaperNode