Skip to main content

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.

NOTE: 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 devises

eyesonMeeting.join(
accessKey,
.......
)
audioManager.start(object : EyesonAudioManager.AudioManagerEvents {
override fun onAudioDeviceChanged(
selectedAudioDevice: EyesonAudioManager.AudioDevice,
availableAudioDevices: Set<EyesonAudioManager.AudioDevice>
) {
// Selected/available devises will be reported here
}
})

Change the output device manually

audioManager.selectAudioDevice(EyesonAudioManager.AudioDevice.SpeakerPhone)

After leaving the meeting also make sure to stop the manager.

audioManager.stop()
eyesonMeeting.leave()

Handling audio focus

By default, audio during a meeting is played without regard to AudioFocus. To avoid 2 or more audio sources being mixed together, your application should properly manage it's AudioFocus.

The EyesonAudioManager provides an easy way to handle the request and going/losing of audio focus.

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)
}
}
})