Skip to content

Releases: twilio/audioswitch

0.1.0

28 Apr 21:48
4a4c8b3
Compare
Choose a tag to compare
0.1.0 Pre-release
Pre-release

This release marks the first iteration of the AudioSwitch library: an Android audio management library for real-time communication apps.

This initial release comes with the following features:

  • Manage audio focus for typical VoIP and Video conferencing use cases.
  • Manage audio input and output devices.
    • Detect changes in available audio devices
    • Enumerate audio devices
    • Select an audio device

Getting Started

To get started using this library, follow the steps below.

Gradle Setup

Download

Add this line as a new Gradle dependency:

implementation 'com.twilio:audioswitch:$version'

AudioDeviceSelector Setup

Instantiate an instance of the AudioDeviceSelector class, passing a reference to the application context.

val audioDeviceSelector = AudioDeviceSelector(applicationContext)

Listen for Devices

To begin listening for live audio device changes, call the start function and pass a lambda that will receive AudioDevices when they become available.

audioDeviceSelector.start { audioDevices, selectedDevice ->
    // TODO update UI with audio devices
}

You can also retrieve the available and selected audio devices manually at any time by calling the following properties:

val devices: List<AudioDevice> = audioDeviceSelector.availableAudioDevices
val selectedDevice: AudioDevice? = audioDeviceSelector.selectedAudioDevice

Note: Don't forget to stop listening for audio devices when no longer needed in order to prevent a memory leak.

audioDeviceSelector.stop()

Select a Device

Before activating an AudioDevice, it needs to be selected first.

devices.find { it is AudioDevice.Speakerphone }?.let { audioDeviceSelector.selectDevice(it) }

If no device is selected, then the library will automatically select a device based on the following priority: BluetoothHeadset -> WiredHeadset -> Earpiece -> Speakerphone.

Activate a Device

Activating a device acquires audio focus with voice communication usage and begins routing audio input/output to the selected device.

audioDeviceSelector.activate()

Make sure to revert back to the prior audio state when it makes sense to do so in your app.

audioDeviceSelector.deactivate()

Note: The stop() function will call deactivate() before closing AudioDeviceSelector resources.