From b41346cdcecf3a7750ba52d86b66b6b39bac7ff7 Mon Sep 17 00:00:00 2001 From: Florian Renaud Date: Mon, 31 Oct 2022 18:42:52 +0100 Subject: [PATCH] Improve player transitions --- .../listening/VoiceBroadcastPlayerImpl.kt | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 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 e6d1c88b1a..ee537b9e61 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 @@ -63,10 +63,6 @@ class VoiceBroadcastPlayerImpl @Inject constructor( private var currentMediaPlayer: MediaPlayer? = null private var nextMediaPlayer: MediaPlayer? = null - set(value) { - field = value - currentMediaPlayer?.setNextMediaPlayer(value) - } private var currentSequence: Int? = null private var fetchPlaylistJob: Job? = null @@ -303,7 +299,7 @@ class VoiceBroadcastPlayerImpl @Inject constructor( } } - private inner class MediaPlayerListener : MediaPlayer.OnInfoListener, MediaPlayer.OnCompletionListener, MediaPlayer.OnErrorListener { + private inner class MediaPlayerListener : MediaPlayer.OnInfoListener, MediaPlayer.OnPreparedListener, MediaPlayer.OnCompletionListener, MediaPlayer.OnErrorListener { override fun onInfo(mp: MediaPlayer, what: Int, extra: Int): Boolean { when (what) { @@ -317,6 +313,17 @@ class VoiceBroadcastPlayerImpl @Inject constructor( return false } + override fun onPrepared(mp: MediaPlayer) { + when (mp) { + currentMediaPlayer -> { + nextMediaPlayer?.let { mp.setNextMediaPlayer(it) } + } + nextMediaPlayer -> { + tryOrNull { currentMediaPlayer?.setNextMediaPlayer(mp) } + } + } + } + override fun onCompletion(mp: MediaPlayer) { if (nextMediaPlayer != null) return val roomId = currentRoomId ?: return