Skip to content

An Android audio management library for real-time communication apps.

License

Notifications You must be signed in to change notification settings

senseobservationsystems/audioswitch

 
 

Repository files navigation

AudioSwitch

CircleCI

An Android audio management library for real-time communication apps.

video-app-screenshots

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

Requirements

Android Studio Version Android API Version Min
3.6+ 16

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'

Pull requests merged to master result in an artifact being published to JFrog OSS Snapshots. You can access these snapshots by adding the following to your gradle file.

maven {
    url 'https://oss.jfrog.org/artifactory/libs-snapshot/'
}

implementation 'com.twilio:audioswitch:$version-SNAPSHOT'

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.

Usage Examples

License

Apache 2.0 license. See LICENSE.txt for details.

About

An Android audio management library for real-time communication apps.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Kotlin 100.0%