diff --git a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt index bf73e6a75..f37de433b 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt @@ -273,7 +273,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions { */ private fun showBottomBar() { if (this::playerBinding.isInitialized && !binding.player.isPlayerLocked) { - playerBinding.exoBottomBar.visibility = View.VISIBLE + playerBinding.bottomBar.visibility = View.VISIBLE } handler.postDelayed(this::showBottomBar, 100) } @@ -818,11 +818,6 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions { private fun prepareExoPlayerView() { exoPlayerView.apply { - setShowSubtitleButton(false) - setShowNextButton(false) - setShowPreviousButton(false) - // controllerShowTimeoutMs = 1500 - controllerHideOnTouch = true useController = false player = exoPlayer } diff --git a/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt b/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt index 4f2fe027e..36e1aad9c 100644 --- a/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt +++ b/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt @@ -89,6 +89,10 @@ internal class CustomExoPlayerView( // saved to only load the playback speed once (for the first video) private var playbackPrefSet = false + private val hideControllerRunnable = Runnable { + hideController() + } + fun initialize( playerViewInterface: OnlinePlayerOptions?, doubleTapOverlayBinding: DoubleTapOverlayBinding, @@ -111,6 +115,9 @@ internal class CustomExoPlayerView( applyCaptionsStyle() initializeAdvancedOptions(context) + // don't let the player view hide its controls automatically + controllerShowTimeoutMs = -1 + if (!playbackPrefSet) { player?.playbackParameters = PlaybackParameters( PlayerHelper.playbackSpeed.toFloat(), @@ -196,12 +203,22 @@ internal class CustomExoPlayerView( override fun hideController() { if (resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) { - // hide all the navigation bars that potentially could have been reopened manually ba the user + // hide all the navigation bars that potentially could have been reopened manually by the user (context as? MainActivity)?.windowHelper?.setFullscreen() } + // remove the callback to hide the controller + handler.removeCallbacks(hideControllerRunnable) super.hideController() } + override fun showController() { + // remove the previous callback from the queue to prevent a flashing behavior + handler.removeCallbacks(hideControllerRunnable) + // automatically hide the controller after 2 seconds + handler.postDelayed(hideControllerRunnable, 2000) + super.showController() + } + override fun onTouchEvent(event: MotionEvent): Boolean { return false } @@ -327,7 +344,7 @@ internal class CustomExoPlayerView( binding.exoTopBarRight.visibility = visibility binding.exoCenterControls.visibility = visibility - binding.exoBottomBar.visibility = visibility + binding.bottomBar.visibility = visibility binding.closeImageButton.visibility = visibility binding.exoTitle.visibility = visibility binding.playPauseBTN.visibility = visibility @@ -555,15 +572,12 @@ internal class CustomExoPlayerView( } // add a margin to the top and the bottom bar in landscape mode for notches - val newMargin = if ( - newConfig?.orientation == Configuration.ORIENTATION_LANDSCAPE - ) { - LANDSCAPE_MARGIN_HORIZONTAL - } else { - 0 + val newMargin = when (newConfig?.orientation) { + Configuration.ORIENTATION_LANDSCAPE -> LANDSCAPE_MARGIN_HORIZONTAL + else -> 0 } - listOf(binding.exoTopBar, binding.exoBottomBar).forEach { + listOf(binding.topBar, binding.bottomBar).forEach { val params = it.layoutParams as MarginLayoutParams params.marginStart = newMargin params.marginEnd = newMargin @@ -574,7 +588,7 @@ internal class CustomExoPlayerView( /** * Load the captions style according to the users preferences */ - fun applyCaptionsStyle() { + private fun applyCaptionsStyle() { val captionStyle = PlayerHelper.getCaptionStyle(context) subtitleView?.apply { setApplyEmbeddedFontSizes(false) diff --git a/app/src/main/res/layout/exo_styled_player_control_view.xml b/app/src/main/res/layout/exo_styled_player_control_view.xml index 97d6bffed..a4fb1cced 100644 --- a/app/src/main/res/layout/exo_styled_player_control_view.xml +++ b/app/src/main/res/layout/exo_styled_player_control_view.xml @@ -10,7 +10,7 @@ android:background="@color/exo_black_opacity_60" />