From 39aa7500de18ad6d360dcc313ef763b260e59b43 Mon Sep 17 00:00:00 2001 From: Jorge Martin Espinosa Date: Tue, 10 Jun 2025 16:17:05 +0200 Subject: [PATCH] Element Call: add delay before selecting the default audio device (#4854) --- .../android/features/call/impl/utils/WebViewAudioManager.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/utils/WebViewAudioManager.kt b/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/utils/WebViewAudioManager.kt index 6ccf840f0f..dc55ff2ac4 100644 --- a/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/utils/WebViewAudioManager.kt +++ b/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/utils/WebViewAudioManager.kt @@ -19,6 +19,7 @@ import androidx.annotation.RequiresApi import androidx.core.content.getSystemService import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.delay import kotlinx.coroutines.launch import kotlinx.serialization.Serializable import kotlinx.serialization.Transient @@ -26,6 +27,7 @@ import kotlinx.serialization.json.Json import timber.log.Timber import java.util.concurrent.Executors import java.util.concurrent.atomic.AtomicBoolean +import kotlin.time.Duration.Companion.milliseconds /** * This class manages the audio devices for a WebView. @@ -221,6 +223,10 @@ class WebViewAudioManager( }, onAudioPlaybackStarted = { coroutineScope.launch(Dispatchers.Main) { + // Even with the callback, it seems like starting the audio takes a bit on the webview side, + // so we add an extra delay here to make sure it's ready + delay(500.milliseconds) + // Calling this ahead of time makes the default audio device to not use the right audio stream setAvailableAudioDevices()