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 {
when (what) {
MediaPlayer.MEDIA_INFO_STARTED_AS_NEXT -> {
playlist.currentSequence++
playlist.currentSequence = playlist.currentSequence?.inc()
currentMediaPlayer = mp
nextMediaPlayer = null
prepareNextMediaPlayer()

View file

@ -24,8 +24,8 @@ class VoiceBroadcastPlaylist(
private val items: MutableList<PlaylistItem> = mutableListOf(),
) : List<PlaylistItem> 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)
}