diff --git a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt index 3ac3d14b..e23dea7b 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt @@ -1835,15 +1835,17 @@ class BaresipService: Service() { handleIncomingCall(call) if (ua.account.answerMode == Api.ANSWERMODE_AUTO) { Log.d(TAG, "Auto-answering external call ${call.callp}") - call.answer() + Handler(Looper.getMainLooper()).postDelayed({ + call.answer() + }, 2000) } - } else { + } + else postServiceEvent(ServiceEvent( "call outgoing", arrayListOf(ua.uap, call.callp), System.nanoTime()) ) - } } fun handleExternalCallRemoved(telecomCall: android.telecom.Call) { @@ -2170,16 +2172,6 @@ class BaresipService: Service() { } } - private fun playUnInterrupted(raw: Int, count: Int) { - val player = MediaPlayer.create(this, raw) - player.setOnCompletionListener { - it.stop() - it.release() - if (count > 1) playUnInterrupted(raw, count - 1) - } - player.start() - } - private fun stopMediaPlayer() { mediaPlayer?.stop() mediaPlayer?.release() diff --git a/app/src/main/kotlin/com/tutpro/baresip/ConnectionService.kt b/app/src/main/kotlin/com/tutpro/baresip/ConnectionService.kt index b85c655f..04c43ea8 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/ConnectionService.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/ConnectionService.kt @@ -2,6 +2,8 @@ package com.tutpro.baresip import android.content.Intent import android.net.Uri +import android.os.Handler +import android.os.Looper import android.telecom.CallAudioState import android.telecom.Connection import android.telecom.ConnectionRequest @@ -78,11 +80,12 @@ class ConnectionService : ConnectionService() { val ua = UserAgent.ofUap(uap) if (ua != null) { + connection.setRinging() if (ua.account.answerMode == Api.ANSWERMODE_AUTO) { Log.d(TAG, "Auto-answering call $callp") - connection.onAnswer() - } else { - connection.setRinging() + Handler(Looper.getMainLooper()).postDelayed({ + connection.onAnswer() + }, 2000) } }