mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-15 06:40:30 +05:30
fix the playing queue
This commit is contained in:
parent
d1351e0f67
commit
845b6fe2ad
@ -78,7 +78,7 @@ class VideoOptionsBottomSheet(
|
|||||||
shareDialog.show(parentFragmentManager, ShareDialog::class.java.name)
|
shareDialog.show(parentFragmentManager, ShareDialog::class.java.name)
|
||||||
}
|
}
|
||||||
context?.getString(R.string.play_next) -> {
|
context?.getString(R.string.play_next) -> {
|
||||||
PlayingQueue.playNext(videoId)
|
PlayingQueue.addAsNext(videoId)
|
||||||
}
|
}
|
||||||
context?.getString(R.string.add_to_queue) -> {
|
context?.getString(R.string.add_to_queue) -> {
|
||||||
PlayingQueue.add(videoId)
|
PlayingQueue.add(videoId)
|
||||||
|
@ -40,7 +40,7 @@ class AutoPlayHelper(
|
|||||||
if (relatedStreams == null || relatedStreams.isEmpty()) return null
|
if (relatedStreams == null || relatedStreams.isEmpty()) return null
|
||||||
var index = 0
|
var index = 0
|
||||||
var nextStreamId: String? = null
|
var nextStreamId: String? = null
|
||||||
while (nextStreamId == null || PlayingQueue.containsBefore(nextStreamId)) {
|
while (nextStreamId == null || PlayingQueue.containsBeforeCurrent(nextStreamId)) {
|
||||||
nextStreamId = relatedStreams[index].url!!.toID()
|
nextStreamId = relatedStreams[index].url!!.toID()
|
||||||
if (index + 1 < relatedStreams.size) {
|
if (index + 1 < relatedStreams.size) {
|
||||||
index += 1
|
index += 1
|
||||||
|
@ -4,17 +4,13 @@ object PlayingQueue {
|
|||||||
private val queue = mutableListOf<String>()
|
private val queue = mutableListOf<String>()
|
||||||
private var currentVideoId: String? = null
|
private var currentVideoId: String? = null
|
||||||
|
|
||||||
fun clear() {
|
|
||||||
queue.clear()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun add(videoId: String) {
|
fun add(videoId: String) {
|
||||||
if (currentVideoId == videoId) return
|
if (currentVideoId == videoId) return
|
||||||
if (queue.contains(videoId)) queue.remove(videoId)
|
if (queue.contains(videoId)) queue.remove(videoId)
|
||||||
queue.add(videoId)
|
queue.add(videoId)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun playNext(videoId: String) {
|
fun addAsNext(videoId: String) {
|
||||||
if (currentVideoId == videoId) return
|
if (currentVideoId == videoId) return
|
||||||
if (queue.contains(videoId)) queue.remove(videoId)
|
if (queue.contains(videoId)) queue.remove(videoId)
|
||||||
queue.add(
|
queue.add(
|
||||||
@ -24,11 +20,10 @@ object PlayingQueue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getNext(): String? {
|
fun getNext(): String? {
|
||||||
val currentIndex = queue.indexOf(currentVideoId)
|
return try {
|
||||||
return if (currentIndex >= queue.size) {
|
queue[currentIndex() + 1]
|
||||||
|
} catch (e: Exception) {
|
||||||
null
|
null
|
||||||
} else {
|
|
||||||
queue[currentIndex + 1]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,18 +36,20 @@ object PlayingQueue {
|
|||||||
return queue.indexOf(currentVideoId) > 0
|
return queue.indexOf(currentVideoId) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
fun contains(videoId: String): Boolean {
|
|
||||||
return queue.contains(videoId)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun containsBefore(videoId: String): Boolean {
|
|
||||||
return queue.contains(videoId) && queue.indexOf(videoId) < queue.indexOf(currentVideoId)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun updateCurrent(videoId: String) {
|
fun updateCurrent(videoId: String) {
|
||||||
currentVideoId = videoId
|
currentVideoId = videoId
|
||||||
queue.add(videoId)
|
queue.add(videoId)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isNotEmpty() = queue.isNotEmpty()
|
fun isNotEmpty() = queue.isNotEmpty()
|
||||||
|
|
||||||
|
fun clear() = queue.clear()
|
||||||
|
|
||||||
|
fun currentIndex() = queue.indexOf(currentVideoId)
|
||||||
|
|
||||||
|
fun contains(videoId: String) = queue.contains(videoId)
|
||||||
|
|
||||||
|
fun containsBeforeCurrent(videoId: String): Boolean {
|
||||||
|
return queue.contains(videoId) && queue.indexOf(videoId) < currentIndex()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user