From 266236c1e5daee19bdb6e632ab74850a30ed3c7e Mon Sep 17 00:00:00 2001 From: Florian Renaud Date: Fri, 4 Nov 2022 23:20:22 +0100 Subject: [PATCH] set playlist.currentSequence null by default --- .../voicebroadcast/listening/VoiceBroadcastPlayerImpl.kt | 2 +- .../voicebroadcast/listening/VoiceBroadcastPlaylist.kt | 8 ++++---- 2 files changed, 5 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 7b8d8c9547..921e0e69ea 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 @@ -296,7 +296,7 @@ class VoiceBroadcastPlayerImpl @Inject constructor( override fun onInfo(mp: MediaPlayer, what: Int, extra: Int): Boolean { when (what) { MediaPlayer.MEDIA_INFO_STARTED_AS_NEXT -> { - playlist.currentSequence++ + playlist.currentSequence = playlist.currentSequence?.inc() currentMediaPlayer = mp nextMediaPlayer = null prepareNextMediaPlayer() diff --git a/vector/src/main/java/im/vector/app/features/voicebroadcast/listening/VoiceBroadcastPlaylist.kt b/vector/src/main/java/im/vector/app/features/voicebroadcast/listening/VoiceBroadcastPlaylist.kt index 5cd6efc28a..ff388c2313 100644 --- a/vector/src/main/java/im/vector/app/features/voicebroadcast/listening/VoiceBroadcastPlaylist.kt +++ b/vector/src/main/java/im/vector/app/features/voicebroadcast/listening/VoiceBroadcastPlaylist.kt @@ -24,8 +24,8 @@ class VoiceBroadcastPlaylist( private val items: MutableList = mutableListOf(), ) : List by items { - var currentSequence = 1 - val currentItem get() = findBySequence(currentSequence) + var currentSequence: Int? = null + val currentItem get() = currentSequence?.let { findBySequence(it) } val duration get() = items.lastOrNull()?.let { it.startTime + it.audioEvent.duration } ?: 0 @@ -47,7 +47,7 @@ class VoiceBroadcastPlaylist( } fun reset() { - currentSequence = 1 + currentSequence = null items.clear() } @@ -59,7 +59,7 @@ class VoiceBroadcastPlaylist( return items.find { it.audioEvent.sequence == sequenceNumber } } - fun getNextItem() = findBySequence(currentSequence.plus(1)) + fun getNextItem() = findBySequence(currentSequence?.plus(1) ?: 1) fun firstOrNull() = findBySequence(1) }