Enhancements
- Updated gradle version to 8.4
- Updated gradle plugin to 8.3.1
- BluetoothHeadsetConnectionListener now can be added to AudioSwitch to notify when bluetooth device has connected or failed to connect.
- BLUETOOTH_CONNECT and/or BLUETOOTH permission have been removed and are optional now. For bluetooth support, permission have to be added to application using AudioSwitch library. If not provided bluetooth device will not appear in the list of available devices and no callbacks will be received for BluetoothHeadsetConnectionListener.
Enhancements
- Updated gradle version to 8.0.2
- Updated gradle plugin to 8.0.2
Bug Fixes
- Fixed issue where some Samsung Galaxy devices (S9, S21) would not route audio through USB headset when MODE_IN_COMMUNICATION is set.
- Fixed issue where IllegalStateException would be thrown when activating selected AudioDevice shortly after starting AudioSwitch.
- Fixed issue where after stopping AudioSwitch while having an active Bluetooth device would result in permanent audio focus gain.
Bug Fixes
- Bluetooth permissions now checks for the device version in case the target version is newer
- Documentation is now available again and integration tests now pass
- Fixed issue where reported Bluetooth device list could be incorrect upon AudioSwitch restart
Bug Fixes
- Fixed issue with lingering EnableBluetoothSCOJob object causing spurious AudioDeviceChangeListener calls after routing switch.
Enhancements
- Dokka dependency upgraded such that documents can be generated successfully again.
- Updated gradle version to 7.0.2
- Updated gradle plugin to 7.0.3
Bug Fixes
- Fixed issue with spurious
AudioDeviceChangedListener
invocations. - Fixed issue where
InvalidStateException
would be triggered duringaudioswitch.stop(..)
if bluetooth permissions were granted after 'AudioSwitch.start()`.
Enhancements
- Updated the library to support Android 12.
- Updated internal dependencies related to Android 12 support.
- Updated compile and target sdk to Android 12 (31).
- Updated gradle to version 4.2.1.
- Snapshots are now published to the Maven Central snapshots repository.
Enhancements
- Updated the library to use Android Gradle Plugin 4.1.1.
- Now published to MavenCentral.
Enhancements
- Added public KDoc documentation for each release. The latest documentation release can be found at https://twilio.github.io/audioswitch/latest
Enhancements
- Added a constructor parameter named
preferredDeviceList
to configure the order in which audio devices are automatically selected and activated whenselectedAudioDevice
is null.
val audioSwitch = AudioSwitch(application, preferredDeviceList = listOf(Speakerphone::class.java, BluetoothHeadset::class.java))
- Updated
compileSdkVersion
andtargetSdkVersion
to Android API version30
.
Enhancements
- Upgraded Kotlin to
1.4.0
. - Improved the Bluetooth headset connection and audio change reliability by registering the
BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED
andBluetoothHeadset.ACTION_AUDIO_STATE_CHANGED
intent actions instead of relying onandroid.bluetooth.BluetoothDevice
andandroid.media.AudioManager
intent actions. - The context provided when constructing
AudioSwitch
can now take any context. Previously theApplicationContext
was required.
Bug Fixes
- Added the internal access modifier to the
SystemClockWrapper
class since it is not meant to be exposed publicly.
- Promotes 0.4.0 to the first stable release of this library.
Enhancements
- Added a constructor parameter to enable logging. This argument is disabled by default.
val audioSwitch = AudioSwitch(context, loggingEnabled = true)
audioSwitch.start { _, _ -> }
- Added another constructor parameter that allows developers to subscribe to system audio focus changes while the library is activated.
val audioSwitch = AudioSwitch(context, audioFocusChangeListener = OnAudioFocusChangeListener { focusChange ->
// Do something with audio focus change
})
audioSwitch.start { _, _ -> }
// Audio focus changes are received after activating
audioSwitch.activate()
Enhancements
- Changed the name of the
AudioDeviceSelector
class toAudioSwitch
. - Added the MODIFY_AUDIO_SETTINGS to the library manifest so it can be automatically consumed by applications.
- Added
AudioSwitch.VERSION
constant so developers can access the version of AudioSwitch at runtime. - Added
AudioSwitch.loggingEnabled
property so developers can configure AudioSwitch logging behavior at runtime. By default, AudioSwitch logging is disabled. Reference the following snippet to enable AudioSwitch logging:
val audioSwitch = AudioSwitch(context)
audioSwitch.loggingEnabled = true
audioSwitch.start { _, _ -> }
Bug Fixes
- Fixed a bug where the audio focus wasn't being returned to the previous audio focus owner on pre Oreo devices.
Enhancements
- Added support for multiple connected bluetooth headsets.
- The library will now accurately display the up to date active bluetooth headset within the
AudiodDeviceSelector
availableAudioDevices
andselectedAudioDevice
functions.- Other connected headsets are not stored by the library at this moment.
- In the event of a failure to connecting audio to a bluetooth headset, the library will revert the selected audio device (this is usually the Earpiece on a phone).
- If a user would like to switch between multiple Bluetooth headsets, then they need to switch the active bluetooth headset from the system Bluetooth settings.
- The newly activated headset will be propagated to the
AudiodDeviceSelector
availableAudioDevices
andselectedAudioDevice
functions.
- The newly activated headset will be propagated to the
- The library will now accurately display the up to date active bluetooth headset within the
Bug Fixes
- Improved the accuracy of the
BluetoothHeadset
within theavailableAudioDevices
returned from theAudioDeviceSelector
when multiple Bluetooth Headsets are connected.
Bug Fixes
- Disabled AAR minification to fix Android Studio issues such as getting stuck in code analysis and not being able to find declarations of AudioSwitch code.
Enhancements
- AAR minification is now enabled for release artifacts.
Bug Fixes
- Fixed a bug where the audio output doesn't automatically route to a newly connected bluetooth headset.
- Fixed a bug where the selected audio device doesn't get routed back to the default audio device when an error occurs when attempting to connect to a headset.
Bug Fixes
- Fixed crash by adding a default bluetooth device name.
Enhancements
- Added the library source to release artifacts. The sources will now be available when jumping to a library class definition in Android Studio.
Bug Fixes
- Added a fix for certain valid bluetooth device classes not being considered as headset devices as reported in issue #16.
- Fixes bug that did not correctly abandon audio request after deactivate
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
To get started using this library, follow the steps below.
Ensure that you have mavenCentral
listed in your project's buildscript repositories section:
buildscript {
repositories {
mavenCentral()
// ...
}
}
Add this line as a new Gradle dependency:
implementation 'com.twilio:audioswitch:$version'
Instantiate an instance of the AudioDeviceSelector class, passing a reference to the application context.
val audioDeviceSelector = AudioDeviceSelector(applicationContext)
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()
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
.
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.