From 3ac761aa89e0a066f9e617a778bfcf1c90f45ea6 Mon Sep 17 00:00:00 2001 From: Juha Heinanen Date: Mon, 1 Nov 2021 10:54:57 +0200 Subject: [PATCH] More media player related enhancements --- .../com/tutpro/baresip/BaresipService.kt | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt index 9b2f6433..7afd2f9c 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt @@ -545,6 +545,7 @@ class BaresipService: Service() { CallHistory.save() ua.account.missedCalls = true } + playUnInterrupted(R.raw.callwaiting, 1) if (!Utils.isVisible()) return newEvent = "call rejected" @@ -748,9 +749,9 @@ class BaresipService: Service() { stopMediaPlayer() when (ev[2]) { "busy" -> - playNTimes(R.raw.busy, 1) + playMedia(R.raw.busy, 1) "error" -> - playNTimes(R.raw.error, 1) + playMedia(R.raw.error, 1) } call.remove() if (Call.calls().size == 0) { @@ -1154,17 +1155,27 @@ class BaresipService: Service() { } } - private fun playNTimes(raw: Int, count: Int) { + private fun playMedia(raw: Int, count: Int) { if (mediaPlayer == null ) { mediaPlayer = MediaPlayer.create(this, raw) mediaPlayer?.setOnCompletionListener { stopMediaPlayer() - if (count > 1) playNTimes(raw, count - 1) + if (count > 1) playMedia(raw, count - 1) } mediaPlayer?.start() } } + 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()