AudioRouterManager manages audio output routing between the speaker / earpiece / wired headset / Bluetooth headset. This page is the API reference; for the full initialization order, auto-switch policies, and best practices, see Audio routing.
Getting and releasing
Get the singleton throughRTCEngine; don’t create it yourself with new:
Instance methods
setAudioRouterCalllback(callback)
Parameters:
callback:AudioRouterCallback, the route change callback implementation.
void).
The method name issetAudioRouterCalllback(Calllbackhas 3ls); call it exactly as spelled in the source.
setAutoChangeAudioRouter(isAutoChange)
setAutoChangeAudioRouter(isAutoChange, false, false), meaning the earpiece has priority over the speaker and a Bluetooth headset has priority over a wired headset.Parameters:
isAutoChange:boolean;truelets the SDK choose the route automatically,falseonly listens without switching automatically.
void).
setAutoChangeAudioRouter(isAutoChange, isPrioritySpeaker, isPriorityWiredEarphone)
Parameters:
isAutoChange:boolean, whether to switch routes automatically.isPrioritySpeaker:boolean;truegives the speaker priority over the earpiece,falsegives the earpiece priority over the speaker.isPriorityWiredEarphone:boolean;truegives a wired headset priority over a Bluetooth headset,falsegives a Bluetooth headset priority over a wired headset.
void).
setMode(mode)
AudioManager (such as MODE_IN_COMMUNICATION). On Android 6.0+, init() doesn’t set the mode automatically, so call it again every time you switch app scenarios.Parameters:
mode:int, theAudioManageraudio mode.
void).
init()
Parameters: None.
Returns: None (
void).
switchAudioRouter(type)
UN_KNOW reselects the most suitable route according to the current auto-switch policy.Parameters:
type:AudioOutputDeviceType, the target output device type.
void).
release(changeMode)
Parameters:
changeMode:boolean;truerestores the audio mode toMODE_NORMALand switches back to the speaker on release;falsedoesn’t restore the mode.
void).
rtcEngine.releaseAudioRouterManager()callsrelease(true)internally.
getExitAudioOutputDevices()
Parameters: None.
Returns:
HashMap<AudioOutputDeviceType, AudioDeviceInfo>, a map from device type to device info.
getActiveAudioOutputDevice()
Parameters: None.
Returns:
Pair<AudioOutputDeviceType, AudioDeviceInfo>; first is the device type, second is the device info.
getAudioRouterCallback()
Parameters: None.
Returns:
AudioRouterCallback, the current callback instance; may be null.
getAudioManager()
AudioManager held internally.Parameters: None.
Returns:
AudioManager.
requestAudioFocus()
Parameters: None.
Returns:
int, the request result (same as the return value of the system AudioManager.requestAudioFocus).
releaseAudioFocus()
Parameters: None.
Returns:
int, the release result.
setFocusChangeListener(listener)
Parameters:
listener:AudioManager.OnAudioFocusChangeListener, the focus change listener.
void).
Static methods
getValidBluetoothName(curName, context, callback)
AudioDeviceInfo.getProductName(). On Android 12+, mind the BLUETOOTH_CONNECT permission.Parameters:
curName:String, the Bluetooth name currently obtained.context:Context, the context.callback:ValidBluetoothNameCallback, the callback for the corrected name.
void).
Enum AudioOutputDeviceType
Callback interfaces
AudioRouterCallback
exitOutputDeviceChange: The list of currently “selectable” output devices changed (headset plugged in or removed, Bluetooth connected or disconnected, and so on).activeOutputDeviceChange: The output device “actually in effect” changed; use this to show the current device in the UI.onAudioBecomingNoisy: The system may produce noise after a route switch (for example, when a headset is unplugged and audio switches to the speaker); you can pause playback or lower the volume here.
ValidBluetoothNameCallback
onValidBluetoothName: Returns the corrected Bluetooth device name.