mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-27 15:30:31 +05:30
Merge pull request #2775 from Bnyro/master
Use custom animation handlers for player controls
This commit is contained in:
commit
9b5150ce26
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -10,7 +10,7 @@
|
||||
android:background="@color/exo_black_opacity_60" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/exo_top_bar"
|
||||
android:id="@+id/top_bar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="top"
|
||||
@ -190,7 +190,7 @@
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@id/exo_bottom_bar"
|
||||
android:id="@+id/bottom_bar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom"
|
||||
@ -301,7 +301,7 @@
|
||||
android:layout_marginBottom="10dp">
|
||||
|
||||
<com.github.libretube.ui.views.MarkableTimeBar
|
||||
android:id="@id/exo_progress"
|
||||
android:id="@+id/exo_progress"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="16dp"
|
||||
app:bar_height="2dp"
|
||||
|
Loading…
x
Reference in New Issue
Block a user