mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-15 06:40:30 +05:30
Merge pull request #2686 from Bnyro/master
Keep queue when entering audio mode
This commit is contained in:
commit
2334363768
@ -134,9 +134,10 @@ class BackgroundMode : Service() {
|
|||||||
videoId = intent?.getStringExtra(IntentData.videoId)!!
|
videoId = intent?.getStringExtra(IntentData.videoId)!!
|
||||||
playlistId = intent.getStringExtra(IntentData.playlistId)
|
playlistId = intent.getStringExtra(IntentData.playlistId)
|
||||||
val position = intent.getLongExtra(IntentData.position, 0L)
|
val position = intent.getLongExtra(IntentData.position, 0L)
|
||||||
|
val keepQueue = intent.getBooleanExtra(IntentData.keepQueue, false)
|
||||||
|
|
||||||
// play the audio in the background
|
// play the audio in the background
|
||||||
loadAudio(videoId, position)
|
loadAudio(videoId, position, keepQueue)
|
||||||
|
|
||||||
PlayingQueue.setOnQueueTapListener { streamItem ->
|
PlayingQueue.setOnQueueTapListener { streamItem ->
|
||||||
streamItem.url?.toID()?.let { playNextVideo(it) }
|
streamItem.url?.toID()?.let { playNextVideo(it) }
|
||||||
@ -168,7 +169,8 @@ class BackgroundMode : Service() {
|
|||||||
*/
|
*/
|
||||||
private fun loadAudio(
|
private fun loadAudio(
|
||||||
videoId: String,
|
videoId: String,
|
||||||
seekToPosition: Long = 0
|
seekToPosition: Long = 0,
|
||||||
|
keepQueue: Boolean = false
|
||||||
) {
|
) {
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
streams = runCatching {
|
streams = runCatching {
|
||||||
@ -176,21 +178,9 @@ class BackgroundMode : Service() {
|
|||||||
}.getOrNull() ?: return@launch
|
}.getOrNull() ?: return@launch
|
||||||
|
|
||||||
// add the playlist video to the queue
|
// add the playlist video to the queue
|
||||||
if (PlayingQueue.isEmpty() && playlistId != null) {
|
if (PlayingQueue.isEmpty() && !keepQueue) updateQueue()
|
||||||
streams?.toStreamItem(videoId)?.let {
|
streams?.toStreamItem(videoId)?.let {
|
||||||
PlayingQueue.insertPlaylist(playlistId!!, it)
|
PlayingQueue.updateCurrent(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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handler.post {
|
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.
|
* Stop the service when app is removed from the task manager.
|
||||||
*/
|
*/
|
||||||
|
@ -581,8 +581,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
|||||||
|
|
||||||
saveWatchPosition()
|
saveWatchPosition()
|
||||||
|
|
||||||
// clear the playing queue and release the player
|
// release the player
|
||||||
PlayingQueue.resetToDefaults()
|
|
||||||
nowPlayingNotification.destroySelfAndPlayer()
|
nowPlayingNotification.destroySelfAndPlayer()
|
||||||
|
|
||||||
activity?.requestedOrientation =
|
activity?.requestedOrientation =
|
||||||
|
@ -21,14 +21,16 @@ object BackgroundHelper {
|
|||||||
videoId: String,
|
videoId: String,
|
||||||
position: Long? = null,
|
position: Long? = null,
|
||||||
playlistId: String? = null,
|
playlistId: String? = null,
|
||||||
channelId: String? = null
|
channelId: String? = null,
|
||||||
|
keepQueue: Boolean? = null
|
||||||
) {
|
) {
|
||||||
// create an intent for the background mode service
|
// create an intent for the background mode service
|
||||||
val intent = Intent(context, BackgroundMode::class.java)
|
val intent = Intent(context, BackgroundMode::class.java)
|
||||||
intent.putExtra(IntentData.videoId, videoId)
|
intent.putExtra(IntentData.videoId, videoId)
|
||||||
intent.putExtra(IntentData.playlistId, playlistId)
|
intent.putExtra(IntentData.playlistId, playlistId)
|
||||||
intent.putExtra(IntentData.channelId, channelId)
|
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
|
// start the background mode as foreground service
|
||||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O) {
|
||||||
|
Loading…
Reference in New Issue
Block a user