set playlist.currentSequence null by default

This commit is contained in:
Florian Renaud 2022-11-04 23:20:22 +01:00
parent 43a112839f
commit 266236c1e5
2 changed files with 5 additions and 5 deletions

View file

@ -296,7 +296,7 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
override fun onInfo(mp: MediaPlayer, what: Int, extra: Int): Boolean { override fun onInfo(mp: MediaPlayer, what: Int, extra: Int): Boolean {
when (what) { when (what) {
MediaPlayer.MEDIA_INFO_STARTED_AS_NEXT -> { MediaPlayer.MEDIA_INFO_STARTED_AS_NEXT -> {
playlist.currentSequence++ playlist.currentSequence = playlist.currentSequence?.inc()
currentMediaPlayer = mp currentMediaPlayer = mp
nextMediaPlayer = null nextMediaPlayer = null
prepareNextMediaPlayer() prepareNextMediaPlayer()

View file

@ -24,8 +24,8 @@ class VoiceBroadcastPlaylist(
private val items: MutableList<PlaylistItem> = mutableListOf(), private val items: MutableList<PlaylistItem> = mutableListOf(),
) : List<PlaylistItem> by items { ) : List<PlaylistItem> by items {
var currentSequence = 1 var currentSequence: Int? = null
val currentItem get() = findBySequence(currentSequence) val currentItem get() = currentSequence?.let { findBySequence(it) }
val duration val duration
get() = items.lastOrNull()?.let { it.startTime + it.audioEvent.duration } ?: 0 get() = items.lastOrNull()?.let { it.startTime + it.audioEvent.duration } ?: 0
@ -47,7 +47,7 @@ class VoiceBroadcastPlaylist(
} }
fun reset() { fun reset() {
currentSequence = 1 currentSequence = null
items.clear() items.clear()
} }
@ -59,7 +59,7 @@ class VoiceBroadcastPlaylist(
return items.find { it.audioEvent.sequence == sequenceNumber } return items.find { it.audioEvent.sequence == sequenceNumber }
} }
fun getNextItem() = findBySequence(currentSequence.plus(1)) fun getNextItem() = findBySequence(currentSequence?.plus(1) ?: 1)
fun firstOrNull() = findBySequence(1) fun firstOrNull() = findBySequence(1)
} }