Skip to content

Instantly share code, notes, and snippets.

@halilozercan
Created January 16, 2020 13:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save halilozercan/05721673692e1748cd90b57940e75625 to your computer and use it in GitHub Desktop.
Save halilozercan/05721673692e1748cd90b57940e75625 to your computer and use it in GitHub Desktop.
typealias OnAudioDeviceChanged = (
selectedAudioDevice: AudioGenie.AudioDevice?,
availableAudioDevices: Set<AudioGenie.AudioDevice>
) -> Unit
val newAudioDevices: MutableSet<AudioDevice> = HashSet()
if (bluetoothManager.state == State.SCO_CONNECTED || bluetoothManager.state == State.SCO_CONNECTING || bluetoothManager.state == State.HEADSET_AVAILABLE
) {
newAudioDevices.add(AudioDevice.BLUETOOTH)
}
if (hasWiredHeadset) {
// If a wired headset is connected, then it is the only possible option.
newAudioDevices.add(AudioDevice.WIRED_HEADSET)
} else {
// No wired headset, hence the audio-device list can contain speaker // phone (on a tablet), or speaker phone and earpiece (on mobile phone).
newAudioDevices.add(AudioDevice.SPEAKER_PHONE)
if (hasEarpiece()) {
newAudioDevices.add(AudioDevice.EARPIECE)
}
}
// Store state which is set to true if the device list has changed.
var audioDeviceSetUpdated = audioDevices != newAudioDevices
// Update the existing audio device set.
audioDevices = newAudioDevices
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment