AudioDeviceManager (object)
Interface that manages audio input/output devices during calls.
Initialization of VICore is required before using this manager. Audio routing starts automatically when a call or conference is active.
Supported device types are defined in AudioDeviceType:
- Earpiece
- Speaker
- Wired headset
- USB headset
- Bluetooth headset
For self-managed ConnectionService integrations on Android 12 (API 31) and above, AudioDeviceManager.setTelecomConnection should be used to route audio through Telecom.
Default audio device:
The earpiece is the default audio device for devices that support telephony, such as Android phones. The speaker is the default audio device for Android tablets. The default audio device type can be changed via AudioDeviceManager.setDefaultAudioDeviceType.
Before a call:
If the audio device is not selected via AudioDeviceManager.selectAudioDevice and the default audio device type is not set via AudioDeviceManager.setDefaultAudioDeviceType, the device is selected according to the following priority order:
- Bluetooth (if connected)
- USB or wired headset (if connected)
- Earpiece (if available)
- Speaker
If an audio device is selected via AudioDeviceManager.selectAudioDevice and then a higher-priority device is connected, the new device is used for the call. For example, if the speaker is selected and a Bluetooth headset is subsequently connected, the Bluetooth device is used.
During a call:
If a new audio device, such as a wired, USB, or Bluetooth headset, is connected, the active audio device is switched to the newly connected device.
If the active audio device is disconnected, the active audio device is selected according to the priority order.
If the active audio device is selected via AudioDeviceManager.selectAudioDevice, the active audio device is switched to the selected device.
Device changes are reported via AudioDeviceListener.onAudioDeviceChanged and AudioDeviceListener.onAudioDeviceListChanged.
Permissions:
Voximplant Android SDK does not require any additional permissions to manage audio devices.
Limitations:
- On Android 11 and below, selecting the earpiece is not possible while a wired or USB headset is connected.
- Voximplant Android SDK does not currently support multiple Bluetooth audio devices.
Methods
- addAudioDeviceListener
- getAudioDeviceOfType
- removeAudioDeviceListener
- selectAudioDevice
- setDefaultAudioDeviceType
- setTelecomConnection
Properties
Methods
addAudioDeviceListener
fun addAudioDeviceListener(listener: AudioDeviceListener): Unit
Adds a listener to receive audio device change notifications.
Parameters
Returns: Unit
getAudioDeviceOfType
fun getAudioDeviceOfType(audioDeviceType: AudioDeviceType): AudioDevice?
Returns the first available audio device of the specified type, or null if no matching device is available.
Useful to get a device before passing it to AudioDeviceManager.selectAudioDevice.
Parameters
Returns: AudioDevice?
removeAudioDeviceListener
fun removeAudioDeviceListener(listener: AudioDeviceListener): Unit
Removes the listener used to handle audio devices changes.
Parameters
Returns: Unit
selectAudioDevice
fun selectAudioDevice(audioDevice: AudioDevice): Unit
Selects the audio device to use before or during a call.
Before a call: selects the device without activating it. The device is activated when the call starts.
During a call: activates the specified device if it is available in AudioDeviceManager.audioDevices.
The selection may be overridden if a higher-priority device is connected later. In that case AudioDeviceListener.onAudioDeviceChanged is triggered. When the call ends, the selection is reset according to the default priority order.
Parameters
Returns: Unit
setDefaultAudioDeviceType
fun setDefaultAudioDeviceType(audioDeviceType: AudioDeviceType): Unit
Sets the default audio device type used when no higher-priority device is connected.
Only AudioDeviceType.Earpiece or AudioDeviceType.Speaker can be set. The earpiece is the default on phones; the speaker is the default on tablets.
Has no effect if the requested type is not present in AudioDeviceManager.audioDevices.
Parameters
Returns: Unit
setTelecomConnection
fun setTelecomConnection(connection: Connection?): Unit
Sets the Telecom Connection used for audio routing when integrating a self-managed ConnectionService.
On Android 12 (API 31) and above, passing a non-null connection enables Telecom-based audio routing. Passing null reverts routing to the default SDK behavior.
This method should be called before each call starts.
The connection should be updated when the active Telecom Connection changes for the next call.
Annotations: RequiresApi
Parameters
Returns: Unit
Properties
audioDevices
val audioDevices: List<AudioDevice>
List of currently available audio devices.
Updated when devices are connected or disconnected. Subscribe to changes via AudioDeviceListener.onAudioDeviceListChanged.
Read-only.
audioFocusListener
var audioFocusListener: AudioFocusListener?
Listener for system audio focus changes during calls.
Assign an AudioFocusListener implementation to receive AudioFocusListener.onAudioFocusChanged callbacks on the main thread.
selectedAudioDevice
val selectedAudioDevice: AudioDevice?
Currently selected audio device.
During a call, it returns the device used for audio playback and capture. When no call is active, it returns the device used for the next call.
Updated automatically when a higher-priority device is connected or the active device is disconnected. Subscribe to changes via AudioDeviceListener.onAudioDeviceChanged. Change the selection manually via AudioDeviceManager.selectAudioDevice.
Read-only.