StereoPannerNode

StereoPannerNode interface of the Web 音频 API represents a simple stereo panner node that can be used to pan an audio stream left or right. It is an AudioNode audio-processing module that positions an incoming audio stream in a stereo image using a low-cost equal-power panning algorithm .

pan property takes a unitless value between -1 (full left pan) and 1 (full right pan). This interface was introduced as a much simpler way to apply a simple panning effect than having to use a full PannerNode .

Number of inputs 1
Number of outputs 1
Channel count mode "clamped-max"
Channel count 2
Channel interpretation "speakers"

构造函数

StereoPannerNode()
Creates a new instance of a StereoPannerNode 对象。

特性

Inherits properties from its parent, AudioNode .

StereoPannerNode.pan 只读
Is an a-rate AudioParam representing the amount of panning to apply.

方法

No specific method; inherits methods from its parent, AudioNode .

范例

In our StereoPannerNode example ( see source code ) HTML we have a simple <audio> element along with a slider <input> to increase and decrease pan value. In the JavaScript we create a MediaElementAudioSourceNode StereoPannerNode , and connect the two together using the connect() method. We then use an oninput event handler to change the value of the StereoPannerNode.pan parameter and update the pan value display when the slider is moved.

Moving the slider left and right while the music is playing pans the music across to the left and right speakers of the output, respectively.

var audioCtx = new (window.AudioContext || window.webkitAudioContext)();
var myAudio = document.querySelector('audio');
var panControl = document.querySelector('.panning-control');
var panValue = document.querySelector('.panning-value');
pre.innerHTML = myScript.innerHTML;
// Create a MediaElementAudioSourceNode
// Feed the HTMLMediaElement into it
var source = audioCtx.createMediaElementSource(myAudio);
// Create a stereo panner
var panNode = audioCtx.createStereoPanner();
// Event handler function to increase panning to the right and left
// when the slider is moved
panControl.oninput = function() {
  panNode.pan.setValueAtTime(panControl.value, audioCtx.currentTime);
  panValue.innerHTML = panControl.value;
}
// connect the MediaElementAudioSourceNode to the panNode
// and the panNode to the destination, so we can play the
// music and adjust the panning using the controls
source.connect(panNode);
panNode.connect(audioCtx.destination);
					

规范

规范 状态 Comment
Web 音频 API
The definition of 'StereoPannerNode' in that specification.
工作草案 初始定义

浏览器兼容性

更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
StereoPannerNode Chrome 41 Edge ≤18 Firefox 37 IE 不支持 No Opera 28 Safari 不支持 No WebView Android 41 Chrome Android 41 Firefox Android 37 Opera Android 28 Safari iOS 不支持 No Samsung Internet Android 4.0
StereoPannerNode() 构造函数 Chrome 55
注意事项
55
注意事项
Before Chrome 59, the default values were not supported.
Edge ≤79 Firefox 53 IE 不支持 No Opera 42 Safari 不支持 No WebView Android 55
注意事项
55
注意事项
Before Chrome 59, the default values were not supported.
Chrome Android 55
注意事项
55
注意事项
Before Chrome 59, the default values were not supported.
Firefox Android 53 Opera Android 42 Safari iOS 不支持 No Samsung Internet Android 6.0
注意事项
6.0
注意事项
Before Samsung Internet 7.0, the default values were not supported.
pan Chrome 41 Edge 12 Firefox 37 IE 不支持 No Opera 28 Safari 不支持 No WebView Android 41 Chrome Android 41 Firefox Android 37 Opera Android 28 Safari iOS 不支持 No Samsung Internet Android 4.0

图例

完整支持
完整支持
不支持
不支持
见实现注意事项。

另请参阅