Wait for voice recording and playback release before call signalling
This commit is contained in:
1 parent
a85d2cc8c7
commit
bb08b20e58
3 files changed
+8
-1
No files matched your search
@@ -216,9 +216,10 @@ object CallController : TelecomCallManager.Listener {
|
||||
if (_state.value?.callId != id || _state.value?.ongoing != true) return@launch
|
||||
LogManager.addLog("INFO", "Call", "media release begins id=$id restoreRadio=$radioToRestore")
|
||||
val radioStopped = RadioAudioEngine.instance().stopForCall()
|
||||
val voiceStopped = AudioRecorderManager.stopAll()
|
||||
StreamController.stopForCall()
|
||||
StreamPlayerEngine.stopForCall()
|
||||
withContext(Dispatchers.IO) { radioStopped.get(); MediaAudioController.awaitIdle() }
|
||||
withContext(Dispatchers.IO) { radioStopped.get(); voiceStopped.forEach { it.get() }; MediaAudioController.awaitIdle() }
|
||||
val current = _state.value
|
||||
if (current?.callId != id || !current.ongoing) {
|
||||
LogManager.addLog("INFO", "Call", "media released after call cancellation id=$id")
|
||||
|
||||
@@ -1747,6 +1747,7 @@ class ChatViewModel : ViewModel() {
|
||||
}
|
||||
|
||||
fun playVoiceMessage(filePath: String, durMs: Int) {
|
||||
if (CallController.blocksMedia()) { LogManager.addLog("WARN", "Voice", "Playback rejected: call owns audio"); return }
|
||||
val cur = _playbackState.value
|
||||
if (cur.filePath == filePath) {
|
||||
if (cur.paused) {
|
||||
@@ -1774,6 +1775,7 @@ class ChatViewModel : ViewModel() {
|
||||
}
|
||||
|
||||
fun seekVoice(filePath: String, seekMs: Int, durMs: Int) {
|
||||
if (CallController.blocksMedia()) { LogManager.addLog("WARN", "Voice", "Seek rejected: call owns audio"); return }
|
||||
audioRecorder.stopPlayback()
|
||||
realPlaybackElapsedMs = seekMs
|
||||
_playbackState.value = PlaybackState(filePath, playing = true, durMs = durMs, elapsedMs = seekMs,
|
||||
|
||||
+4
@@ -112,4 +112,8 @@ class RadioAudioEngine {
|
||||
}
|
||||
object StreamPlayerEngine { val viewing = MutableStateFlow(false); fun stopForCall() { viewing.value = false } }
|
||||
object MediaAudioController { var beforeIdle: () -> Unit = {}; fun awaitIdle() { beforeIdle() } }
|
||||
object AudioRecorderManager {
|
||||
var stopped: CompletableFuture<Unit> = CompletableFuture.completedFuture(Unit)
|
||||
fun stopAll() = listOf(stopped)
|
||||
}
|
||||
enum class MediaAudioProfile { AUTO, PHONE, WIRED, BLUETOOTH }
|
||||
Reference in new issue
Block a user