草案
此页面不完整。

createMediaStreamTrackSource() 方法在 AudioContext interface creates and returns a MediaStreamTrackAudioSourceNode which represents an audio source whose data comes from the specified MediaStreamTrack .

This differs from createMediaStreamSource() , which creates a MediaStreamAudioSourceNode whose audio comes from the audio track in a specified MediaStream whose id is first, lexicographically (alphabetically).

句法

var audioCtx = new AudioContext();
var track = audioCtx.createMediaStreamTrackSource(track);
					

参数

track
MediaStreamTrack to use as the source of all audio data for the new node.

返回值

A MediaStreamTrackAudioSourceNode object which acts as a source for audio data found in the specified audio track.

范例

在此范例中, getUserMedia() is used to request access to the user's microphone. Once that access is attained, an audio context is established and a MediaStreamTrackAudioSourceNode is created using createMediaStreamTrackSource() , taking its audio from the first audio track in the stream returned by getUserMedia() .

Then a BiquadFilterNode is created using createBiquadFilter() , and it's configured as desired to perform a lowshelf filter on the audio coming from the source. The output from the microphone is then routed into the new biquad filter, and the filter's output is in turn routed to the audio context's destination .

navigator.mediaDevices.getUserMedia ({audio: true, video: false})
.then(function(stream) {
  audio.srcObject = stream;
  audio.onloadedmetadata = function(e) {
    audio.play();
    audio.muted = true;
  };
  let audioCtx = new AudioContext();
  let source = audioCtx.createMediaStreamSource(stream);
  let biquadFilter = audioCtx.createBiquadFilter();
  biquadFilter.type = "lowshelf";
  biquadFilter.frequency.value = 3000;
  biquadFilter.gain.value = 20;
  source.connect(biquadFilter);
  biquadFilter.connect(audioCtx.destination);
})
.catch(function(err) {
  // Handle getUserMedia() error
});
					

规范

规范 状态 注释
Web 音频 API
The definition of 'createMediaStreamTrackSource()' in that specification.
工作草案

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
createMediaStreamTrackSource Chrome 不支持 No Edge 不支持 No Firefox 68 注意事项
68 注意事项
Firefox 68 implements the updated standard's definition of the "first" audio track; now the first track is the one whose ID comes first lexicographically.
IE 不支持 No Opera 不支持 No Safari 不支持 No WebView Android 不支持 No Chrome Android 不支持 No Firefox Android 68 注意事项
68 注意事项
Firefox 68 implements the updated standard's definition of the "first" audio track; now the first track is the one whose ID comes first lexicographically.
Opera Android 不支持 No Safari iOS 不支持 No Samsung Internet Android 不支持 No

图例

完整支持

完整支持

不支持

不支持

见实现注意事项。

另请参阅

元数据

  • 最后修改: