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_AUDIO_LANGUAGE,
|
||||||
SET_SUBTITLE,
|
SET_SUBTITLE,
|
||||||
SET_SB_AUTO_SKIP_ENABLED,
|
SET_SB_AUTO_SKIP_ENABLED,
|
||||||
|
PLAY_VIDEO_BY_ID
|
||||||
}
|
}
|
@ -154,6 +154,14 @@ abstract class AbstractPlayerService : MediaLibraryService(), MediaLibrarySessio
|
|||||||
setPreferredTextLanguage(subtitle?.code)
|
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()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the stream source and start the playback.
|
||||||
|
*
|
||||||
|
* This function should base its actions on the videoId variable.
|
||||||
|
*/
|
||||||
abstract suspend fun startPlayback()
|
abstract suspend fun startPlayback()
|
||||||
|
|
||||||
fun saveWatchPosition() {
|
fun saveWatchPosition() {
|
||||||
|
@ -25,11 +25,13 @@ import com.github.libretube.databinding.ExoStyledPlayerControlViewBinding
|
|||||||
import com.github.libretube.db.DatabaseHolder.Database
|
import com.github.libretube.db.DatabaseHolder.Database
|
||||||
import com.github.libretube.db.obj.DownloadChapter
|
import com.github.libretube.db.obj.DownloadChapter
|
||||||
import com.github.libretube.enums.FileType
|
import com.github.libretube.enums.FileType
|
||||||
|
import com.github.libretube.enums.PlayerCommand
|
||||||
import com.github.libretube.enums.PlayerEvent
|
import com.github.libretube.enums.PlayerEvent
|
||||||
import com.github.libretube.extensions.serializableExtra
|
import com.github.libretube.extensions.serializableExtra
|
||||||
import com.github.libretube.helpers.BackgroundHelper
|
import com.github.libretube.helpers.BackgroundHelper
|
||||||
import com.github.libretube.helpers.PlayerHelper
|
import com.github.libretube.helpers.PlayerHelper
|
||||||
import com.github.libretube.helpers.WindowHelper
|
import com.github.libretube.helpers.WindowHelper
|
||||||
|
import com.github.libretube.services.AbstractPlayerService
|
||||||
import com.github.libretube.services.VideoOfflinePlayerService
|
import com.github.libretube.services.VideoOfflinePlayerService
|
||||||
import com.github.libretube.ui.base.BaseActivity
|
import com.github.libretube.ui.base.BaseActivity
|
||||||
import com.github.libretube.ui.fragments.DownloadTab
|
import com.github.libretube.ui.fragments.DownloadTab
|
||||||
@ -135,10 +137,6 @@ class OfflinePlayerActivity : BaseActivity() {
|
|||||||
binding = ActivityOfflinePlayerBinding.inflate(layoutInflater)
|
binding = ActivityOfflinePlayerBinding.inflate(layoutInflater)
|
||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
|
|
||||||
PlayingQueue.setOnQueueTapListener { streamItem ->
|
|
||||||
playNextVideo(streamItem.url ?: return@setOnQueueTapListener)
|
|
||||||
}
|
|
||||||
|
|
||||||
val arguments = bundleOf(
|
val arguments = bundleOf(
|
||||||
IntentData.downloadTab to DownloadTab.VIDEO,
|
IntentData.downloadTab to DownloadTab.VIDEO,
|
||||||
IntentData.videoId to videoId
|
IntentData.videoId to videoId
|
||||||
@ -161,9 +159,13 @@ class OfflinePlayerActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun playNextVideo(videoId: String) {
|
private fun playNextVideo(nextId: String) {
|
||||||
this.videoId = videoId
|
this.videoId = nextId
|
||||||
playVideo()
|
|
||||||
|
playerController.sendCustomCommand(
|
||||||
|
AbstractPlayerService.runPlayerActionCommand,
|
||||||
|
bundleOf(PlayerCommand.PLAY_VIDEO_BY_ID.name to nextId)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initializePlayerView() {
|
private fun initializePlayerView() {
|
||||||
|
@ -139,13 +139,14 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
|
|
||||||
// data and objects stored for the player
|
// data and objects stored for the player
|
||||||
private lateinit var streams: Streams
|
private lateinit var streams: Streams
|
||||||
val isShort get() = run {
|
val isShort
|
||||||
val heightGreaterThanWidth = streams.videoStreams.firstOrNull()?.let {
|
get() = run {
|
||||||
(it.height ?: 0) > (it.width ?: 0)
|
val heightGreaterThanWidth = streams.videoStreams.firstOrNull()?.let {
|
||||||
}
|
(it.height ?: 0) > (it.width ?: 0)
|
||||||
|
}
|
||||||
|
|
||||||
PlayingQueue.getCurrent()?.isShort == true || heightGreaterThanWidth == true
|
PlayingQueue.getCurrent()?.isShort == true || heightGreaterThanWidth == true
|
||||||
}
|
}
|
||||||
|
|
||||||
// if null, it's been set to automatic
|
// if null, it's been set to automatic
|
||||||
private var fullscreenResolution: Int? = null
|
private var fullscreenResolution: Int? = null
|
||||||
@ -205,11 +206,11 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
|
|
||||||
when (event) {
|
when (event) {
|
||||||
PlayerEvent.Next -> {
|
PlayerEvent.Next -> {
|
||||||
playNextVideo(PlayingQueue.getNext())
|
PlayingQueue.getNext()?.let { playNextVideo(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerEvent.Prev -> {
|
PlayerEvent.Prev -> {
|
||||||
playNextVideo(PlayingQueue.getPrev())
|
PlayingQueue.getPrev()?.let { playNextVideo(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerEvent.Background -> {
|
PlayerEvent.Background -> {
|
||||||
@ -309,6 +310,12 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
|
|
||||||
mediaMetadata.extras?.getString(IntentData.videoId)?.let {
|
mediaMetadata.extras?.getString(IntentData.videoId)?.let {
|
||||||
videoId = it
|
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)
|
val maybeStreams: Streams? = mediaMetadata.extras?.parcelable(IntentData.streams)
|
||||||
@ -655,11 +662,11 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
playerBinding.skipPrev.setOnClickListener {
|
playerBinding.skipPrev.setOnClickListener {
|
||||||
playNextVideo(PlayingQueue.getPrev())
|
PlayingQueue.getPrev()?.let { prev -> playNextVideo(prev) }
|
||||||
}
|
}
|
||||||
|
|
||||||
playerBinding.skipNext.setOnClickListener {
|
playerBinding.skipNext.setOnClickListener {
|
||||||
playNextVideo(PlayingQueue.getNext())
|
PlayingQueue.getNext()?.let { next -> playNextVideo(next) }
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.relPlayerDownload.setOnClickListener {
|
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) {
|
private fun playNextVideo(nextId: String) {
|
||||||
if (nextId == null && PlayingQueue.repeatMode == Player.REPEAT_MODE_ONE) {
|
playerController.sendCustomCommand(
|
||||||
playerController.seekTo(0)
|
AbstractPlayerService.runPlayerActionCommand,
|
||||||
return
|
bundleOf(PlayerCommand.PLAY_VIDEO_BY_ID.name to nextId)
|
||||||
}
|
)
|
||||||
|
|
||||||
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()
|
|
||||||
|
|
||||||
// close comment bottom sheet if opened for next video
|
// close comment bottom sheet if opened for next video
|
||||||
activity?.supportFragmentManager?.fragments?.filterIsInstance<CommentsSheet>()
|
activity?.supportFragmentManager?.fragments?.filterIsInstance<CommentsSheet>()
|
||||||
@ -1081,9 +1075,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
binding.autoplayCountdown.startCountdown {
|
binding.autoplayCountdown.startCountdown {
|
||||||
runCatching {
|
PlayingQueue.getNext()?.let { playNextVideo(it) }
|
||||||
playNextVideo()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@ import android.app.PendingIntent
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
|
||||||
import androidx.core.app.PendingIntentCompat
|
import androidx.core.app.PendingIntentCompat
|
||||||
import androidx.media3.session.CommandButton
|
import androidx.media3.session.CommandButton
|
||||||
import androidx.media3.session.DefaultMediaNotificationProvider
|
import androidx.media3.session.DefaultMediaNotificationProvider
|
||||||
@ -46,8 +45,6 @@ class NowPlayingNotification(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.e("get intent", intentActivity.name)
|
|
||||||
|
|
||||||
return PendingIntentCompat
|
return PendingIntentCompat
|
||||||
.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT, false)
|
.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT, false)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user