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);
Most phones have two audio routes: the earpiece at the top and the speaker at the bottom. You can call this method to set the default audio route, determining whether audio plays through the earpiece or speaker when no external audio device is connected. In different scenarios, the system's default audio routes are:
  • Voice call: Earpiece.
  • Audio live streaming: Speaker.
  • Video call: Speaker.
  • Video live streaming: Speaker.
Note: After setting the default audio route with this method, the actual audio route will automatically switch based on the connection status of external audio devices (e.g., wired or Bluetooth headsets).

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);
Note: This method only sets the audio route for the current channel and does not affect the default audio route. If the user leaves the current channel and joins another, the default audio route will be used. If the user uses external audio playback devices such as Bluetooth or wired headsets, this method has no effect. The SDK plays audio through the external device. When multiple external devices are connected, the SDK plays audio through the last connected device.

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.

Note: Using this method together with setEnableSpeakerphone may cause conflicts. It is recommended to use only setRouteInCommunicationMode.

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.