Stereo
enableSoundPositionIndication
Enables or disables stereo panning for remote users.
public abstract int enableSoundPositionIndication(boolean enabled);
Call this method before joining a channel. Once enabled, the local user can call setRemoteVoicePosition to track the position of remote users.
Parameters
- enabled
- Whether to enable stereo panning for remote users:
- true: Enable stereo panning.
- false: Disable stereo panning.
Return Values
- 0: Success.
- < 0: Failure.
setRemoteVoicePosition
Sets the spatial position and volume of a remote user's voice.
public abstract int setRemoteVoicePosition(int uid, double pan, double gain);
This method sets the spatial position and volume of a remote user's voice by adjusting the balance between the left and right audio channels. This helps the local user identify the position of the remote user and creates a sense of space. This method is suitable for large-scale multiplayer online games, such as battle royale games.
- To make this method take effect, call enableSoundPositionIndication before joining a channel to enable stereo sound positioning for remote users.
- For optimal voice positioning, it is recommended to use wired headphones.
- Call this method after joining a channel.
Parameters
- uid
- The ID of the remote user.
- pan
- The spatial position of the remote user's voice. The range is from -1.0 to 1.0:
- 0.0: (Default) The remote voice comes from the front.
- -1.0: The remote voice comes from the left.
- 1.0: The remote voice comes from the right.
- gain
- The volume of the remote user. The range is from 0.0 to 100.0. The default value is 100.0 (original volume of the remote user). The smaller the value, the lower the volume.
Return Values
- 0: Success.
- < 0: Failure.
setRemoteVoicePositionEx
Sets the 2D position and volume of the remote user's voice.
public abstract int setRemoteVoicePositionEx(int uid, double pan, double gain, RtcConnection connection);
This method sets the voice position and volume of a remote user. After calling this method, the difference between the left and right audio channels allows you to perceive the remote user's position in real time, creating a sense of space. This method is suitable for large-scale multiplayer online games, such as battle royale games.
- For the best voice positioning effect, Agora recommends using wired headphones.
- Call this method after joining the channel.
Scenario
This method applies to multi-channel scenarios.
Parameters
- uid
- Remote user ID.
- pan
- The voice position of the remote user. The value range is from -1.0 to 1.0:
- -1.0: The remote voice comes from the left.
- 0.0: (Default) The remote voice comes from the front.
- 1.0: The remote voice comes from the right.
- gain
- The volume of the remote user. The value range is from 0.0 to 100.0, with a default value of 100.0. The smaller the value, the lower the volume.
- connection
- Connection information. See RtcConnection.
Return Values
- 0: Success.
- < 0: Failure.