Rate this page:

AudioDeviceManager

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:

  1. Earpiece
  2. Speaker
  3. Wired headset
  4. USB headset
  5. 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:

  1. Bluetooth (if connected)
  2. USB or wired headset (if connected)
  3. Earpiece (if available)
  4. 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:

  1. On Android 11 and below, selecting the earpiece is not possible while a wired or USB headset is connected.
  2. Voximplant Android SDK does not currently support multiple Bluetooth audio devices.

Methods

addAudioDeviceListener
Copy URL
fun addAudioDeviceListener(listener: 

AudioDeviceListener

):

Unit

Adds a listener to receive audio device change notifications.

Parameters

Returns

  • type:

    Unit

getAudioDeviceOfType
Copy URL
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

removeAudioDeviceListener
Copy URL
fun removeAudioDeviceListener(listener: 

AudioDeviceListener

):

Unit

Removes the listener used to handle audio devices changes.

Parameters

Returns

  • type:

    Unit

selectAudioDevice
Copy URL
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

  • type:

    Unit

setDefaultAudioDeviceType
Copy URL
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

  • audioDeviceType:

    AudioDeviceType

    Audio device type to use as the default between earpiece and speaker

Returns

  • type:

    Unit

setTelecomConnection
Copy URL
@RequiresApi
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.

Parameters

  • connection:

    Connection?

    Telecom Connection, or null to reset routing to the default SDK behavior

Returns

  • type:

    Unit

Props

audioDevices
Read-only
Copy URL
val audioDevices: 

List<AudioDevice>

List of currently available audio devices.

Updated when devices are connected or disconnected. Subscribe to changes via AudioDeviceListener.onAudioDeviceListChanged.

Returns

audioFocusListener
Copy URL
var audioFocusListener: 

AudioFocusListener?

Listener for system audio focus changes during calls.

Assign an AudioFocusListener implementation to receive AudioFocusListener.onAudioFocusChanged callbacks on the main thread.

Returns

selectedAudioDevice
Read-only
Copy URL
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.

Returns

Rate this page: