From bc00b12b8cedd1529b92fc7ad87b82db64de628c Mon Sep 17 00:00:00 2001 From: Kelvin <kelvin@futo.org> Date: Fri, 8 Dec 2023 11:17:36 +0100 Subject: [PATCH] Hide prev/next for single item queue, Fullscreen next/prev button show/hide, Bypass loop for next controls --- .../mainactivity/main/VideoDetailView.kt | 9 +++++---- .../futo/platformplayer/states/StatePlayer.kt | 16 ++++++++++------ .../views/video/FutoVideoPlayer.kt | 2 ++ 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/VideoDetailView.kt b/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/VideoDetailView.kt index 10b49582..f59a6f0f 100644 --- a/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/VideoDetailView.kt +++ b/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/VideoDetailView.kt @@ -468,7 +468,7 @@ class VideoDetailView : ConstraintLayout { nextVideo(); }; _player.onDatasourceError.subscribe(::onDataSourceError); - _player.onNext.subscribe { nextVideo(true, true) }; + _player.onNext.subscribe { nextVideo(true, true, true) }; _player.onPrevious.subscribe { prevVideo(true) }; _minimize_controls_play.setOnClickListener { handlePlay(); }; @@ -546,7 +546,7 @@ class VideoDetailView : ConstraintLayout { MediaControlReceiver.onLowerVolumeReceived.subscribe(this) { handleLowerVolume() }; MediaControlReceiver.onPlayReceived.subscribe(this) { handlePlay() }; MediaControlReceiver.onPauseReceived.subscribe(this) { handlePause() }; - MediaControlReceiver.onNextReceived.subscribe(this) { nextVideo(true) }; + MediaControlReceiver.onNextReceived.subscribe(this) { nextVideo(true, true, true) }; MediaControlReceiver.onPreviousReceived.subscribe(this) { prevVideo(true) }; MediaControlReceiver.onCloseReceived.subscribe(this) { Logger.i(TAG, "MediaControlReceiver.onCloseReceived") @@ -1332,6 +1332,7 @@ class VideoDetailView : ConstraintLayout { if(video.isLive && video.live == null && !video.video.videoSources.any()) startLiveTry(video); + _player.updateNextPrevious(); updateMoreButtons(); } fun loadLiveChat(video: IPlatformVideoDetails) { @@ -1551,9 +1552,9 @@ class VideoDetailView : ConstraintLayout { } } - fun nextVideo(forceLoop: Boolean = false, withoutRemoval: Boolean = false): Boolean { + fun nextVideo(forceLoop: Boolean = false, withoutRemoval: Boolean = false, bypassVideoLoop: Boolean = false): Boolean { Logger.i(TAG, "nextVideo") - var next = StatePlayer.instance.nextQueueItem(withoutRemoval || _player.duration < 100 || (_player.position.toFloat() / _player.duration) < 0.9); + var next = StatePlayer.instance.nextQueueItem(withoutRemoval || _player.duration < 100 || (_player.position.toFloat() / _player.duration) < 0.9, bypassVideoLoop); if(next == null && forceLoop) next = StatePlayer.instance.restartQueue(); if(next != null) { diff --git a/app/src/main/java/com/futo/platformplayer/states/StatePlayer.kt b/app/src/main/java/com/futo/platformplayer/states/StatePlayer.kt index 717bf4df..ccbaacd6 100644 --- a/app/src/main/java/com/futo/platformplayer/states/StatePlayer.kt +++ b/app/src/main/java/com/futo/platformplayer/states/StatePlayer.kt @@ -375,6 +375,9 @@ class StatePlayer { fun getPrevQueueItem(forceLoop: Boolean = false) : IPlatformVideo? { synchronized(_queue) { + if(_queue.size == 1) + return null; + val shuffledQueue = _queueShuffled; val queue = if (queueShuffle && shuffledQueue != null) { shuffledQueue; @@ -386,7 +389,7 @@ class StatePlayer { if(_queuePosition == -1 && queue.isNotEmpty()) return queue[0]; //Standard Behavior - if(_queuePosition - 1 > 0) + if(_queuePosition - 1 >= 0) return queue[_queuePosition - 1]; //Repeat Behavior (End of queue) if(_queuePosition - 1 < 0 && queue.isNotEmpty() && (forceLoop || queueRepeat)) @@ -395,9 +398,10 @@ class StatePlayer { return null; } fun getNextQueueItem(forceLoop: Boolean = false) : IPlatformVideo? { - if(loopVideo) - return currentVideo; synchronized(_queue) { + if(_queue.size == 1) + return null; + val shuffledQueue = _queueShuffled; val queue = if (queueShuffle && shuffledQueue != null) { shuffledQueue; @@ -420,11 +424,11 @@ class StatePlayer { fun restartQueue() : IPlatformVideo? { synchronized(_queue) { _queuePosition = -1; - return nextQueueItem(); + return nextQueueItem(false, true); } }; - fun nextQueueItem(withoutRemoval: Boolean = false) : IPlatformVideo? { - if(loopVideo) + fun nextQueueItem(withoutRemoval: Boolean = false, bypassVideoLoop: Boolean = false) : IPlatformVideo? { + if(loopVideo && !bypassVideoLoop) return currentVideo; synchronized(_queue) { if (_queue.isEmpty()) diff --git a/app/src/main/java/com/futo/platformplayer/views/video/FutoVideoPlayer.kt b/app/src/main/java/com/futo/platformplayer/views/video/FutoVideoPlayer.kt index f724f637..df179723 100644 --- a/app/src/main/java/com/futo/platformplayer/views/video/FutoVideoPlayer.kt +++ b/app/src/main/java/com/futo/platformplayer/views/video/FutoVideoPlayer.kt @@ -325,7 +325,9 @@ class FutoVideoPlayer : FutoVideoPlayerBase { val vidPrev = StatePlayer.instance.getPrevQueueItem(true); val vidNext = StatePlayer.instance.getNextQueueItem(true); _buttonNext.visibility = if (vidNext != null) View.VISIBLE else View.GONE + _buttonNext_fullscreen.visibility = if (vidNext != null) View.VISIBLE else View.GONE _buttonPrevious.visibility = if (vidPrev != null) View.VISIBLE else View.GONE + _buttonPrevious_fullscreen.visibility = if (vidPrev != null) View.VISIBLE else View.GONE } private val _currentChapterUpdateInterval: Long = 1000L / Settings.instance.playback.getChapterUpdateFrames(); -- GitLab