LibreTube/app/src/main/java/com/github/libretube/util/PlayingQueue.kt

28 lines
574 B
Kotlin
Raw Normal View History

2022-09-19 23:37:55 +05:30
package com.github.libretube.util
object PlayingQueue {
val queue = mutableListOf<String>()
2022-09-19 23:43:25 +05:30
val currentVideoId: String? = null
2022-09-19 23:37:55 +05:30
fun clear() {
queue.clear()
}
fun add(videoId: String) {
queue.add(videoId)
}
2022-09-19 23:43:25 +05:30
fun playNext(nextVideoId: String) {
2022-09-19 23:37:55 +05:30
queue.add(
queue.indexOf(currentVideoId),
nextVideoId
)
}
2022-09-19 23:43:25 +05:30
fun getNext(): String? {
val currentIndex = queue.indexOf(currentVideoId)
return if (currentIndex > queue.size) null
else queue[currentIndex + 1]
}
2022-09-19 23:37:55 +05:30
}