From 9dba6d7c8c4e3497b3ef146d67a1edbae2c64788 Mon Sep 17 00:00:00 2001 From: Florian Renaud Date: Thu, 24 Nov 2022 17:24:36 +0100 Subject: [PATCH] Fix issue on live playback detection --- .../listening/VoiceBroadcastPlayerImpl.kt | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/voicebroadcast/listening/VoiceBroadcastPlayerImpl.kt b/vector/src/main/java/im/vector/app/features/voicebroadcast/listening/VoiceBroadcastPlayerImpl.kt index f04b85859b..bd541d23e4 100644 --- a/vector/src/main/java/im/vector/app/features/voicebroadcast/listening/VoiceBroadcastPlayerImpl.kt +++ b/vector/src/main/java/im/vector/app/features/voicebroadcast/listening/VoiceBroadcastPlayerImpl.kt @@ -66,7 +66,7 @@ class VoiceBroadcastPlayerImpl @Inject constructor( private var nextMediaPlayer: MediaPlayer? = null private var isPreparingNextPlayer: Boolean = false - private var currentVoiceBroadcastEvent: VoiceBroadcastEvent? = null + private var mostRecentVoiceBroadcastEvent: VoiceBroadcastEvent? = null override var currentVoiceBroadcast: VoiceBroadcast? = null override var isLiveListening: Boolean = false @@ -121,7 +121,7 @@ class VoiceBroadcastPlayerImpl @Inject constructor( // Clear playlist playlist.reset() - currentVoiceBroadcastEvent = null + mostRecentVoiceBroadcastEvent = null currentVoiceBroadcast = null } @@ -159,7 +159,7 @@ class VoiceBroadcastPlayerImpl @Inject constructor( if (event == null) { stop() } else { - currentVoiceBroadcastEvent = event + mostRecentVoiceBroadcastEvent = event updateLiveListeningMode() } } @@ -204,7 +204,7 @@ class VoiceBroadcastPlayerImpl @Inject constructor( val playlistItem = when { position != null -> playlist.findByPosition(position) - currentVoiceBroadcastEvent?.isLive.orFalse() -> playlist.lastOrNull() + mostRecentVoiceBroadcastEvent?.isLive.orFalse() -> playlist.lastOrNull() else -> playlist.firstOrNull() } val content = playlistItem?.audioEvent?.content ?: run { Timber.w("## VoiceBroadcastPlayer: No content to play"); return } @@ -346,7 +346,7 @@ class VoiceBroadcastPlayerImpl @Inject constructor( private fun updateLiveListeningMode(seekPosition: Int? = null) { isLiveListening = when { // the current voice broadcast is not live (ended) - currentVoiceBroadcastEvent?.isLive?.not().orFalse() -> false + mostRecentVoiceBroadcastEvent?.isLive != true -> false // the player is stopped or paused playingState == State.IDLE || playingState == State.PAUSED -> false seekPosition != null -> { @@ -412,13 +412,11 @@ class VoiceBroadcastPlayerImpl @Inject constructor( override fun onCompletion(mp: MediaPlayer) { if (nextMediaPlayer != null) return - val content = currentVoiceBroadcastEvent?.content - val isLive = content?.isLive.orFalse() - if (!isLive && content?.lastChunkSequence == playlist.currentSequence) { + if (isLiveListening || mostRecentVoiceBroadcastEvent?.content?.lastChunkSequence == playlist.currentSequence) { + playingState = State.BUFFERING + } else { // We'll not receive new chunks anymore so we can stop the live listening stop() - } else { - playingState = State.BUFFERING } }