--- title: AudioListener slug: Web/API/AudioListener translation_of: Web/API/AudioListener ---
{{ APIRef("Web Audio API") }}
AudioListener
接口代表了人听音乐场景时声音的位置和方向, 和用于音频空间化。 所有{{domxref("PannerNode")}} 相对于 AudioListener
的空间化储存在{{domxref("BaseAudioContext.listener")}} 属性里.
特别需要注意的是一个环境中只能有一个收听者而且这不是{{domxref("AudioNode")}}.
position,forward和up值是以不同的语法设置和检索的。检索是通过访问来实现的,比如说 AudioListener.positionX
,设置相同属性时可以通过使用 AudioListener.positionX.value
来完成。 这就是为什么他们不被标记为只读, 这在规范的接口定义中就是这么说的.
positionX
, positionY
, 和 positionZ
) 值一样。前方和上方值互相线性无关。默认值是 0.positionX
, positionY
, and positionZ
) values. The forward and up values are linearly independent of each other. The default is 0.positionX
, positionY
, and positionZ
) values. The forward and up values are linearly independent of each other. The default is -1.positionX
, positionY
, 和positionZ
) 值一样。 前方和上方值线性无关。默认值是 0.positionX
, positionY
, and positionZ
) values. The forward and up values are linearly independent of each other. The default is 1.positionX
, positionY
, and positionZ
) values. The forward and up values are linearly independent of each other. The default is 0.Note: Although these methods are deprecated they are currently the only way to set the orientation and position in Firefox, Internet Explorer and Safari.
In a previous version of the specification, the dopplerFactor
and speedOfSound
properties and the setPosition()
method could be used to control the doppler effect applied to {{domxref("AudioBufferSourceNode")}}s connected downstream — these would be pitched up and down according to the relative speed of the {{domxref("PannerNode")}} and the {{domxref("AudioListener")}}. These features had a number of problems:
Because of these issues, these properties and methods have been removed.
The setOrientation()
and setPosition()
methods have been replaced by setting their property value equivilents. For example setPosition(x, y, z)
can be achieved by setting positionX.value
, positionY.value
, and positionZ.value
respectively.
{{page("/en-US/docs/Web/API/AudioContext.createPanner","Example")}}
Specification | Status | Comment |
---|---|---|
{{SpecName('Web Audio API', '#audiolistener', 'AudioListener')}} | {{Spec2('Web Audio API')}} |
{{Compat("api.AudioListener")}}