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