From 09925699b763ae596e8021e6526abf85f74f1912 Mon Sep 17 00:00:00 2001 From: Giacomo Pacini Date: Thu, 19 Dec 2024 12:04:36 +0100 Subject: [PATCH] added a boolean backgroundPlayAllowed, so that startPlayback continues only when that parameter is true. It is set to true only when it is called to play a consecutive voice message. Signed-off-by: Giacomo Pacini --- .../java/com/nextcloud/talk/chat/ChatActivity.kt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt b/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt index 85d56fc90..c1a895b05 100644 --- a/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt @@ -1205,7 +1205,7 @@ class ChatActivity : } } - private fun setUpWaveform(message: ChatMessage, thenPlay: Boolean = true) { + private fun setUpWaveform(message: ChatMessage, thenPlay: Boolean = true, backgroundPlayAllowed : Boolean = false) { val filename = message.selectedIndividualHashMap!!["name"] val file = File(context.cacheDir, filename!!) if (file.exists() && message.voiceMessageFloatArray == null) { @@ -1216,11 +1216,11 @@ class ChatActivity : appPreferences.saveWaveFormForFile(filename, r.toTypedArray()) message.voiceMessageFloatArray = r withContext(Dispatchers.Main) { - startPlayback(message, thenPlay) + startPlayback(message, thenPlay, backgroundPlayAllowed) } } } else { - startPlayback(message, thenPlay) + startPlayback(message, thenPlay, backgroundPlayAllowed) } } @@ -1614,14 +1614,14 @@ class ChatActivity : } } - private fun startPlayback(message: ChatMessage, doPlay: Boolean = true) { - //if (!active) { + private fun startPlayback(message: ChatMessage, doPlay: Boolean = true, backgroundPlayAllowed : Boolean = false) { + if (!active && !backgroundPlayAllowed) { // don't begin to play voice message if screen is not visible anymore. // this situation might happen if file is downloading but user already left the chatview. // If user returns to chatview, the old chatview instance is not attached anymore // and he has to click the play button again (which is considered to be okay) - // return - //} + return + } initMediaPlayer(message)