Add the queue to the background mode

This commit is contained in:
Bnyro 2022-10-23 16:04:15 +02:00
parent 2e4b6beb2f
commit 3599d97a1f
3 changed files with 9 additions and 8 deletions

View File

@ -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,

View File

@ -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 {

View File

@ -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!!))