AudioListener
The AudioListener interface represents the position and orientation of the person listening to the audio scene.
It is used for 3D spatialization: all PannerNode objects spatialize sound in relation to the context's listener.
AudioListener is not an AudioNode — it has no inputs, outputs, or connect()/disconnect() methods. It only exposes nine AudioParam properties.
Every BaseAudioContext exposes a single listener through its read-only listener property — you never construct one yourself.
- The
positionX,positionYandpositionZparameters represent the location of the listener in 3D Cartesian coordinate space. - The
forwardX,forwardYandforwardZparameters represent a direction vector in 3D space — which direction the listener's "nose" is pointing. - The
upX,upYandupZparameters represent the direction the top of the listener's head is pointing.
The forward and up vectors are expected to be linearly independent.
Example
import { AudioContext } from 'react-native-audio-api';
const ctx = new AudioContext();
const listener = ctx.listener;
// Move the listener 3 meters along the x axis.
listener.positionX.value = 3;
// Or automate the movement over time.
listener.positionX.linearRampToValueAtTime(10, ctx.currentTime + 2);
Properties
All properties are AudioParams with minValue/maxValue spanning the full single-precision float range (approximately ±3.4028235e38), a-rate automation.
Look here for more detailed explanation what each property means.
| Name | Type | Default value | Description | |
|---|---|---|---|---|
positionX | AudioParam | 0 | x-coordinate of the listener's position. | Read only |
positionY | AudioParam | 0 | y-coordinate of the listener's position. | Read only |
positionZ | AudioParam | 0 | z-coordinate of the listener's position. | Read only |
forwardX | AudioParam | 0 | x-component of the listener's forward direction. | Read only |
forwardY | AudioParam | 0 | y-component of the listener's forward direction. | Read only |
forwardZ | AudioParam | -1 | z-component of the listener's forward direction. | Read only |
upX | AudioParam | 0 | x-component of the listener's up direction. | Read only |
upY | AudioParam | 1 | y-component of the listener's up direction. | Read only |
upZ | AudioParam | 0 | z-component of the listener's up direction. | Read only |
Remarks
- Used by
PannerNodefor 3D spatialization relative to the listener.