mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 07:50:31 +05:30
Add the queue to the background mode
This commit is contained in:
parent
2e4b6beb2f
commit
3599d97a1f
@ -3,8 +3,7 @@ package com.github.libretube.extensions
|
||||
import com.github.libretube.api.obj.StreamItem
|
||||
import com.github.libretube.api.obj.Streams
|
||||
|
||||
fun Streams?.toStreamItem(videoId: String): StreamItem {
|
||||
if (this == null) return StreamItem()
|
||||
fun Streams.toStreamItem(videoId: String): StreamItem {
|
||||
return StreamItem(
|
||||
url = videoId,
|
||||
title = title,
|
||||
|
@ -145,8 +145,6 @@ class BackgroundMode : Service() {
|
||||
videoId: String,
|
||||
seekToPosition: Long = 0
|
||||
) {
|
||||
// append the video to the playing queue
|
||||
PlayingQueue.add(streams.toStreamItem(videoId))
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
try {
|
||||
streams = RetrofitInstance.api.getStreams(videoId)
|
||||
@ -156,9 +154,13 @@ class BackgroundMode : Service() {
|
||||
|
||||
// add the playlist video to the queue
|
||||
if (playlistId != null && PlayingQueue.isEmpty()) {
|
||||
PlayingQueue.insertPlaylist(playlistId!!, streams.toStreamItem(videoId))
|
||||
streams?.toStreamItem(videoId)
|
||||
?.let { PlayingQueue.insertPlaylist(playlistId!!, it) }
|
||||
} else {
|
||||
PlayingQueue.updateCurrent(streams.toStreamItem(videoId))
|
||||
streams?.toStreamItem(videoId)?.let { PlayingQueue.updateCurrent(it) }
|
||||
streams?.relatedStreams?.toTypedArray()?.let {
|
||||
PlayingQueue.add(*it)
|
||||
}
|
||||
}
|
||||
|
||||
handler.post {
|
||||
|
@ -405,7 +405,7 @@ class PlayerFragment : BaseFragment() {
|
||||
}
|
||||
|
||||
playerBinding.queueToggle.visibility = View.VISIBLE
|
||||
playerBinding.queueToggle.setOnClickListener {
|
||||
playerBinding.queueToggle.setOnClickListener {
|
||||
PlayingQueueSheet().show(childFragmentManager, null)
|
||||
}
|
||||
|
||||
@ -643,7 +643,7 @@ class PlayerFragment : BaseFragment() {
|
||||
return@launchWhenCreated
|
||||
}
|
||||
|
||||
if (PlayingQueue.size() == 0) {
|
||||
if (PlayingQueue.isEmpty()) {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
if (playlistId != null) {
|
||||
PlayingQueue.insertPlaylist(playlistId!!, streams.toStreamItem(videoId!!))
|
||||
|
Loading…
x
Reference in New Issue
Block a user