mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 16:30:31 +05:30
fix: queue buttons dont work
This commit is contained in:
parent
76d7c622f8
commit
6ed0bfe0b1
@ -8,4 +8,5 @@ enum class PlayerCommand {
|
||||
SET_AUDIO_LANGUAGE,
|
||||
SET_SUBTITLE,
|
||||
SET_SB_AUTO_SKIP_ENABLED,
|
||||
PLAY_VIDEO_BY_ID
|
||||
}
|
@ -154,6 +154,14 @@ abstract class AbstractPlayerService : MediaLibraryService(), MediaLibrarySessio
|
||||
setPreferredTextLanguage(subtitle?.code)
|
||||
}
|
||||
}
|
||||
|
||||
args.containsKey(PlayerCommand.PLAY_VIDEO_BY_ID.name) -> {
|
||||
videoId = args.getString(PlayerCommand.PLAY_VIDEO_BY_ID.name) ?: return
|
||||
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
startPlayback()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -273,6 +281,11 @@ abstract class AbstractPlayerService : MediaLibraryService(), MediaLibrarySessio
|
||||
.build()
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the stream source and start the playback.
|
||||
*
|
||||
* This function should base its actions on the videoId variable.
|
||||
*/
|
||||
abstract suspend fun startPlayback()
|
||||
|
||||
fun saveWatchPosition() {
|
||||
|
@ -25,11 +25,13 @@ import com.github.libretube.databinding.ExoStyledPlayerControlViewBinding
|
||||
import com.github.libretube.db.DatabaseHolder.Database
|
||||
import com.github.libretube.db.obj.DownloadChapter
|
||||
import com.github.libretube.enums.FileType
|
||||
import com.github.libretube.enums.PlayerCommand
|
||||
import com.github.libretube.enums.PlayerEvent
|
||||
import com.github.libretube.extensions.serializableExtra
|
||||
import com.github.libretube.helpers.BackgroundHelper
|
||||
import com.github.libretube.helpers.PlayerHelper
|
||||
import com.github.libretube.helpers.WindowHelper
|
||||
import com.github.libretube.services.AbstractPlayerService
|
||||
import com.github.libretube.services.VideoOfflinePlayerService
|
||||
import com.github.libretube.ui.base.BaseActivity
|
||||
import com.github.libretube.ui.fragments.DownloadTab
|
||||
@ -135,10 +137,6 @@ class OfflinePlayerActivity : BaseActivity() {
|
||||
binding = ActivityOfflinePlayerBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
PlayingQueue.setOnQueueTapListener { streamItem ->
|
||||
playNextVideo(streamItem.url ?: return@setOnQueueTapListener)
|
||||
}
|
||||
|
||||
val arguments = bundleOf(
|
||||
IntentData.downloadTab to DownloadTab.VIDEO,
|
||||
IntentData.videoId to videoId
|
||||
@ -161,9 +159,13 @@ class OfflinePlayerActivity : BaseActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun playNextVideo(videoId: String) {
|
||||
this.videoId = videoId
|
||||
playVideo()
|
||||
private fun playNextVideo(nextId: String) {
|
||||
this.videoId = nextId
|
||||
|
||||
playerController.sendCustomCommand(
|
||||
AbstractPlayerService.runPlayerActionCommand,
|
||||
bundleOf(PlayerCommand.PLAY_VIDEO_BY_ID.name to nextId)
|
||||
)
|
||||
}
|
||||
|
||||
private fun initializePlayerView() {
|
||||
|
@ -139,7 +139,8 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
||||
|
||||
// data and objects stored for the player
|
||||
private lateinit var streams: Streams
|
||||
val isShort get() = run {
|
||||
val isShort
|
||||
get() = run {
|
||||
val heightGreaterThanWidth = streams.videoStreams.firstOrNull()?.let {
|
||||
(it.height ?: 0) > (it.width ?: 0)
|
||||
}
|
||||
@ -205,11 +206,11 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
||||
|
||||
when (event) {
|
||||
PlayerEvent.Next -> {
|
||||
playNextVideo(PlayingQueue.getNext())
|
||||
PlayingQueue.getNext()?.let { playNextVideo(it) }
|
||||
}
|
||||
|
||||
PlayerEvent.Prev -> {
|
||||
playNextVideo(PlayingQueue.getPrev())
|
||||
PlayingQueue.getPrev()?.let { playNextVideo(it) }
|
||||
}
|
||||
|
||||
PlayerEvent.Background -> {
|
||||
@ -309,6 +310,12 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
||||
|
||||
mediaMetadata.extras?.getString(IntentData.videoId)?.let {
|
||||
videoId = it
|
||||
// fix: if the fragment is recreated, play the current video, and not the initial one
|
||||
arguments?.run {
|
||||
val playerData =
|
||||
parcelable<PlayerData>(IntentData.playerData)!!.copy(videoId = videoId)
|
||||
putParcelable(IntentData.playerData, playerData)
|
||||
}
|
||||
}
|
||||
|
||||
val maybeStreams: Streams? = mediaMetadata.extras?.parcelable(IntentData.streams)
|
||||
@ -655,11 +662,11 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
||||
}
|
||||
|
||||
playerBinding.skipPrev.setOnClickListener {
|
||||
playNextVideo(PlayingQueue.getPrev())
|
||||
PlayingQueue.getPrev()?.let { prev -> playNextVideo(prev) }
|
||||
}
|
||||
|
||||
playerBinding.skipNext.setOnClickListener {
|
||||
playNextVideo(PlayingQueue.getNext())
|
||||
PlayingQueue.getNext()?.let { next -> playNextVideo(next) }
|
||||
}
|
||||
|
||||
binding.relPlayerDownload.setOnClickListener {
|
||||
@ -984,26 +991,13 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be used for autoplay and manually skipping to the next video.
|
||||
* Manually skip to another video.
|
||||
*/
|
||||
private fun playNextVideo(nextId: String? = null) {
|
||||
if (nextId == null && PlayingQueue.repeatMode == Player.REPEAT_MODE_ONE) {
|
||||
playerController.seekTo(0)
|
||||
return
|
||||
}
|
||||
|
||||
if (!PlayerHelper.isAutoPlayEnabled(playlistId != null) && nextId == null) return
|
||||
|
||||
videoId = nextId ?: PlayingQueue.getNext() ?: return
|
||||
|
||||
// fix: if the fragment is recreated, play the current video, and not the initial one
|
||||
arguments?.run {
|
||||
val playerData = parcelable<PlayerData>(IntentData.playerData)!!.copy(videoId = videoId)
|
||||
putParcelable(IntentData.playerData, playerData)
|
||||
}
|
||||
|
||||
// start to play the next video
|
||||
playVideo()
|
||||
private fun playNextVideo(nextId: String) {
|
||||
playerController.sendCustomCommand(
|
||||
AbstractPlayerService.runPlayerActionCommand,
|
||||
bundleOf(PlayerCommand.PLAY_VIDEO_BY_ID.name to nextId)
|
||||
)
|
||||
|
||||
// close comment bottom sheet if opened for next video
|
||||
activity?.supportFragmentManager?.fragments?.filterIsInstance<CommentsSheet>()
|
||||
@ -1081,9 +1075,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
||||
}
|
||||
}
|
||||
binding.autoplayCountdown.startCountdown {
|
||||
runCatching {
|
||||
playNextVideo()
|
||||
}
|
||||
PlayingQueue.getNext()?.let { playNextVideo(it) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,6 @@ import android.app.PendingIntent
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import androidx.core.app.PendingIntentCompat
|
||||
import androidx.media3.session.CommandButton
|
||||
import androidx.media3.session.DefaultMediaNotificationProvider
|
||||
@ -46,8 +45,6 @@ class NowPlayingNotification(
|
||||
}
|
||||
}
|
||||
|
||||
Log.e("get intent", intentActivity.name)
|
||||
|
||||
return PendingIntentCompat
|
||||
.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT, false)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user