Web 音频 API
's
MediaStreamTrackAudioSourceNode()
constructor creates and returns a new
MediaStreamTrackAudioSourceNode
object whose audio is taken from the
MediaStreamTrack
specified in the given options object.
Another way to create a
MediaStreamTrackAudioSourceNode
is to call the
AudioContext.createMediaStreamTrackSource()
method, specifying the
MediaStreamTrack
from which you want to obtain audio.
audioTrackNode = new MediaStreamTrackAudioSourceNode(context, options);
context
AudioContext
representing the audio context you want the node to be associated with.
选项
A
MediaStreamTrackAudioSourceOptions
object defining the properties you want the
MediaStreamTrackAudioSourceNode
to have:
mediaStreamTrack
MediaStreamTrack
from which to take audio data for this node's output.
新的
MediaStreamTrackAudioSourceNode
object representing the audio node whose media is obtained from the specified media track.
NotSupportedError
context
is not an
AudioContext
.
InvalidStateError
MediaStreamTrack
isn't an audio track (that is, its
kind
property isn't
audio
.
此范例使用
getUserMedia()
to obtain access to the user's camera, then creates a new
MediaStreamAudioSourceNode
from the first audio track provided by the device.
let audioCtx = new (window.AudioContext || window.webkitAudioContext)();
if (navigator.mediaDevices.getUserMedia) {
navigator.mediaDevices.getUserMedia (
{
audio: true,
video: false
}).then(function(stream) {
let options = {
mediaStreamTrack: stream.getAudioTracks()[0];
}
let source = new MediaStreamTrackAudioSourceNode(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!');
}
| 规范 | 状态 | 注释 |
|---|---|---|
|
Web 音频 API
The definition of 'MediaStreamTrackAudioSourceNode()' in that specification. |
工作草案 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
MediaStreamTrackAudioSourceNode()
构造函数
|
Chrome No | Edge No |
Firefox
68
|
IE No | Opera No | Safari No | WebView Android No | Chrome Android No |
Firefox Android
68
|
Opera Android No | Safari iOS No | Samsung Internet Android No |
完整支持
不支持
见实现注意事项。
MediaStreamTrackAudioSourceNode
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
MediaStreamAudioDestinationNode
MediaStreamAudioSourceNode
OfflineAudioCompletionEvent
OfflineAudioContext
OscillatorNode
PannerNode
PeriodicWave
StereoPannerNode
WaveShaperNode