Audio Route
isSpeakerphoneEnabled
Checks whether the speaker is enabled for audio playback.
public abstract boolean isSpeakerphoneEnabled();
Timing
You can call this method before or after joining a channel.
Return Values
- true: The speaker is enabled, and audio will play through the speaker.
- false: The speaker is not enabled, and audio will play through other devices such as a headset or earpiece.
setDefaultAudioRoutetoSpeakerphone
Sets the default audio playback route.
public abstract int setDefaultAudioRoutetoSpeakerphone(boolean defaultToSpeaker);
- Voice call: Earpiece.
- Audio live streaming: Speaker.
- Video call: Speaker.
- Video live streaming: Speaker.
Timing
Call this method before joining a channel. If you need to change the audio route after joining a channel, call setEnableSpeakerphone.
Parameters
- defaultToSpeaker
- Whether to set the speaker as the default audio route:
- true: Set the speaker as the default audio route.
- false: Set the earpiece as the default audio route.
Return Values
- 0: Success.
- < 0: Failure.
setEnableSpeakerphone
Sets whether to switch the audio route to the speaker.
public abstract int setEnableSpeakerphone(boolean enabled);
Scenario
If the SDK's default audio route or the setting from setDefaultAudioRoutetoSpeakerphone does not meet your needs, you can call this method to switch the current audio route.
Timing
Call this method after joining a channel.
Parameters
- enabled
- Whether to enable the speaker:
- true: Enable device state monitoring, audio route is speaker.
- false: Disable device state monitoring, audio route is earpiece.
Return Values
- 0: Success.
- < 0: Failure.
setRouteInCommunicationMode
Sets the audio playback route in communication audio mode.
public abstract int setRouteInCommunicationMode(int route);
This method switches the audio route from a Bluetooth headset to the earpiece, wired headset, or speaker.
Timing
You can call this method before or after joining a channel.
Parameters
- route
- The audio playback route you want to use:
- -1: Default audio route.
- 0: Headset with microphone.
- 1: Earpiece.
- 2: Headset without microphone.
- 3: Built-in speaker.
- 4: (Not supported) External speaker.
- 5: Bluetooth headset.
- 6: USB device.
Return Values
- 0: Success.
- < 0: Failure.
onAudioRouteChanged
Callback when the local audio route changes.
public void onAudioRouteChanged(int routing) {}
Trigger Timing
This callback is triggered when the local audio route changes.
Parameters
- routing
- The current audio route.
AUDIO_ROUTE_DEFAULT(-1): Default audio route.AUDIO_ROUTE_HEADSET(0): Headset with microphone.AUDIO_ROUTE_EARPIECE(1): Earpiece.AUDIO_ROUTE_HEADSETNOMIC(2): Headset without microphone.AUDIO_ROUTE_SPEAKERPHONE(3): Built-in speaker.AUDIO_ROUTE_LOUDSPEAKER(4): External speaker (reserved).AUDIO_ROUTE_BLUETOOTH_DEVICE_HFP(5): Bluetooth device using HFP protocol.AUDIO_ROUTE_BLUETOOTH_DEVICE_A2DP(10): Bluetooth device using A2DP protocol.