davidliu

Main thread call for audioSwitch selectDevice

... ... @@ -57,7 +57,7 @@ constructor(private val context: Context) : AudioHandler {
override fun start() {
if (audioSwitch == null) {
handler.removeCallbacksAndMessages(null)
handler.post {
handler.postAtFrontOfQueue {
val switch = AudioSwitch(
context = context,
loggingEnabled = loggingEnabled,
... ... @@ -73,7 +73,7 @@ constructor(private val context: Context) : AudioHandler {
override fun stop() {
handler.removeCallbacksAndMessages(null)
handler.post {
handler.postAtFrontOfQueue {
audioSwitch?.stop()
audioSwitch = null
}
... ... @@ -86,8 +86,14 @@ constructor(private val context: Context) : AudioHandler {
get() = audioSwitch?.availableAudioDevices ?: listOf()
fun selectDevice(audioDevice: AudioDevice?) {
if (Looper.myLooper() == Looper.getMainLooper()) {
audioSwitch?.selectDevice(audioDevice)
} else {
handler.post {
audioSwitch?.selectDevice(audioDevice)
}
}
}
companion object {
private val defaultOnAudioFocusChangeListener by lazy(LazyThreadSafetyMode.NONE) {
... ...