mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 06:10:31 +05:30
Keep the queue when entering the audio only mode
This commit is contained in:
parent
552131bd2c
commit
773a41d830
@ -134,9 +134,10 @@ class BackgroundMode : Service() {
|
||||
videoId = intent?.getStringExtra(IntentData.videoId)!!
|
||||
playlistId = intent.getStringExtra(IntentData.playlistId)
|
||||
val position = intent.getLongExtra(IntentData.position, 0L)
|
||||
val keepQueue = intent.getBooleanExtra(IntentData.keepQueue, false)
|
||||
|
||||
// play the audio in the background
|
||||
loadAudio(videoId, position)
|
||||
loadAudio(videoId, position, keepQueue)
|
||||
|
||||
PlayingQueue.setOnQueueTapListener { streamItem ->
|
||||
streamItem.url?.toID()?.let { playNextVideo(it) }
|
||||
@ -168,7 +169,8 @@ class BackgroundMode : Service() {
|
||||
*/
|
||||
private fun loadAudio(
|
||||
videoId: String,
|
||||
seekToPosition: Long = 0
|
||||
seekToPosition: Long = 0,
|
||||
keepQueue: Boolean = false
|
||||
) {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
streams = runCatching {
|
||||
@ -176,21 +178,9 @@ class BackgroundMode : Service() {
|
||||
}.getOrNull() ?: return@launch
|
||||
|
||||
// add the playlist video to the queue
|
||||
if (PlayingQueue.isEmpty() && playlistId != null) {
|
||||
streams?.toStreamItem(videoId)?.let {
|
||||
PlayingQueue.insertPlaylist(playlistId!!, it)
|
||||
}
|
||||
} else if (PlayingQueue.isEmpty() && channelId != null) {
|
||||
streams?.toStreamItem(videoId)?.let {
|
||||
PlayingQueue.insertChannel(channelId!!, it)
|
||||
}
|
||||
} else {
|
||||
streams?.toStreamItem(videoId)?.let {
|
||||
PlayingQueue.updateCurrent(it)
|
||||
}
|
||||
streams?.relatedStreams?.toTypedArray()?.let {
|
||||
if (PlayerHelper.autoInsertRelatedVideos) PlayingQueue.add(*it)
|
||||
}
|
||||
if (PlayingQueue.isEmpty() && !keepQueue) updateQueue()
|
||||
streams?.toStreamItem(videoId)?.let {
|
||||
PlayingQueue.updateCurrent(it)
|
||||
}
|
||||
|
||||
handler.post {
|
||||
@ -371,6 +361,22 @@ class BackgroundMode : Service() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateQueue() {
|
||||
if (playlistId != null) {
|
||||
streams?.toStreamItem(videoId)?.let {
|
||||
PlayingQueue.insertPlaylist(playlistId!!, it)
|
||||
}
|
||||
} else if (channelId != null) {
|
||||
streams?.toStreamItem(videoId)?.let {
|
||||
PlayingQueue.insertChannel(channelId!!, it)
|
||||
}
|
||||
} else {
|
||||
streams?.relatedStreams?.toTypedArray()?.let {
|
||||
if (PlayerHelper.autoInsertRelatedVideos) PlayingQueue.add(*it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop the service when app is removed from the task manager.
|
||||
*/
|
||||
|
@ -21,14 +21,16 @@ object BackgroundHelper {
|
||||
videoId: String,
|
||||
position: Long? = null,
|
||||
playlistId: String? = null,
|
||||
channelId: String? = null
|
||||
channelId: String? = null,
|
||||
keepQueue: Boolean? = null
|
||||
) {
|
||||
// create an intent for the background mode service
|
||||
val intent = Intent(context, BackgroundMode::class.java)
|
||||
intent.putExtra(IntentData.videoId, videoId)
|
||||
intent.putExtra(IntentData.playlistId, playlistId)
|
||||
intent.putExtra(IntentData.channelId, channelId)
|
||||
intent.putExtra("position", position)
|
||||
intent.putExtra(IntentData.position, position)
|
||||
intent.putExtra(IntentData.keepQueue, keepQueue)
|
||||
|
||||
// start the background mode as foreground service
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O) {
|
||||
|
Loading…
Reference in New Issue
Block a user