Audio manager
Provides an implementation for automatic/manual audio routing during a call.
Permissions
Starting with Android 12 the runtime permission BLUETOOTH_CONNECT
is needed in order to list/use connected Bluetooth devices. If the permission is not granted, Bluetooth devices can not be handled. Prior to Android 12 the BLUETOOTH
is automatically granted.
Usage
Create an instance of EyesonAudioManager
. By default, the output device priority will be Bluetooth > WiredHeadset > SpeakerPhone > Earpiece.
When a wired headset is connected it is not possible to select earpiece as it will be overruled by the headset.
val audioManager = EyesonAudioManager(applicationContext)
When you join a meeting also start the manager and provide a listener to receive updated to selected/available devices
eyesonMeeting.join(
accessKey,
.......
)
audioManager.start(object : EyesonAudioManager.AudioManagerEvents {
override fun onAudioDeviceChanged(
selectedAudioDevice: EyesonAudioManager.AudioDevice,
availableAudioDevices: Set<EyesonAudioManager.AudioDevice>
) {
// Selected/available devices will be reported here
}
})
Change the output device manually
audioManager.selectAudioDevice(EyesonAudioManager.AudioDevice.SpeakerPhone)
When you leave a meeting, ensure you stop the audio manager to properly release any audio resources. Always call the stop()
method before leaving the meeting to prevent potential audio-related issues.
audioManager.stop()
eyesonMeeting.leave()
Handling audio focus
The SDK's audio management system operates independently of Android's AudioFocus by default. For optimal audio experience, it's recommended to implement proper AudioFocus management in your application to prevent multiple audio sources from playing simultaneously, which can create an unpleasant listening experience for users.
The EyesonAudioManager
provides a streamlined interface for requesting, managing, and responding to changes in audio focus. By utilizing the provided listener callback, your application can appropriately handle various audio focus states, ensuring a seamless audio experience for users during calls.
EyesonAudioManager(application, audioFocusChangeListener = { focusChange ->
when (focusChange) {
AudioManager.AUDIOFOCUS_GAIN -> {
setRemoteAudioEnabled(_remoteAudioActive.value)
}
AudioManager.AUDIOFOCUS_LOSS -> {
// Permanently lost audio focus. No further callbacks will be received.
// Call [EyesonAudioManage.requestAudioFocus] to request focus again
}
AudioManager.AUDIOFOCUS_LOSS_TRANSIENT -> {
eyesonMeeting.setRemoteAudioEnabled(false)
}
}
})