mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-27 23:40:33 +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() {
|
private fun showBottomBar() {
|
||||||
if (this::playerBinding.isInitialized && !binding.player.isPlayerLocked) {
|
if (this::playerBinding.isInitialized && !binding.player.isPlayerLocked) {
|
||||||
playerBinding.exoBottomBar.visibility = View.VISIBLE
|
playerBinding.bottomBar.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
handler.postDelayed(this::showBottomBar, 100)
|
handler.postDelayed(this::showBottomBar, 100)
|
||||||
}
|
}
|
||||||
@ -818,11 +818,6 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
|||||||
|
|
||||||
private fun prepareExoPlayerView() {
|
private fun prepareExoPlayerView() {
|
||||||
exoPlayerView.apply {
|
exoPlayerView.apply {
|
||||||
setShowSubtitleButton(false)
|
|
||||||
setShowNextButton(false)
|
|
||||||
setShowPreviousButton(false)
|
|
||||||
// controllerShowTimeoutMs = 1500
|
|
||||||
controllerHideOnTouch = true
|
|
||||||
useController = false
|
useController = false
|
||||||
player = exoPlayer
|
player = exoPlayer
|
||||||
}
|
}
|
||||||
|
@ -89,6 +89,10 @@ internal class CustomExoPlayerView(
|
|||||||
// saved to only load the playback speed once (for the first video)
|
// saved to only load the playback speed once (for the first video)
|
||||||
private var playbackPrefSet = false
|
private var playbackPrefSet = false
|
||||||
|
|
||||||
|
private val hideControllerRunnable = Runnable {
|
||||||
|
hideController()
|
||||||
|
}
|
||||||
|
|
||||||
fun initialize(
|
fun initialize(
|
||||||
playerViewInterface: OnlinePlayerOptions?,
|
playerViewInterface: OnlinePlayerOptions?,
|
||||||
doubleTapOverlayBinding: DoubleTapOverlayBinding,
|
doubleTapOverlayBinding: DoubleTapOverlayBinding,
|
||||||
@ -111,6 +115,9 @@ internal class CustomExoPlayerView(
|
|||||||
applyCaptionsStyle()
|
applyCaptionsStyle()
|
||||||
initializeAdvancedOptions(context)
|
initializeAdvancedOptions(context)
|
||||||
|
|
||||||
|
// don't let the player view hide its controls automatically
|
||||||
|
controllerShowTimeoutMs = -1
|
||||||
|
|
||||||
if (!playbackPrefSet) {
|
if (!playbackPrefSet) {
|
||||||
player?.playbackParameters = PlaybackParameters(
|
player?.playbackParameters = PlaybackParameters(
|
||||||
PlayerHelper.playbackSpeed.toFloat(),
|
PlayerHelper.playbackSpeed.toFloat(),
|
||||||
@ -196,12 +203,22 @@ internal class CustomExoPlayerView(
|
|||||||
|
|
||||||
override fun hideController() {
|
override fun hideController() {
|
||||||
if (resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
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()
|
(context as? MainActivity)?.windowHelper?.setFullscreen()
|
||||||
}
|
}
|
||||||
|
// remove the callback to hide the controller
|
||||||
|
handler.removeCallbacks(hideControllerRunnable)
|
||||||
super.hideController()
|
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 {
|
override fun onTouchEvent(event: MotionEvent): Boolean {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -327,7 +344,7 @@ internal class CustomExoPlayerView(
|
|||||||
|
|
||||||
binding.exoTopBarRight.visibility = visibility
|
binding.exoTopBarRight.visibility = visibility
|
||||||
binding.exoCenterControls.visibility = visibility
|
binding.exoCenterControls.visibility = visibility
|
||||||
binding.exoBottomBar.visibility = visibility
|
binding.bottomBar.visibility = visibility
|
||||||
binding.closeImageButton.visibility = visibility
|
binding.closeImageButton.visibility = visibility
|
||||||
binding.exoTitle.visibility = visibility
|
binding.exoTitle.visibility = visibility
|
||||||
binding.playPauseBTN.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
|
// add a margin to the top and the bottom bar in landscape mode for notches
|
||||||
val newMargin = if (
|
val newMargin = when (newConfig?.orientation) {
|
||||||
newConfig?.orientation == Configuration.ORIENTATION_LANDSCAPE
|
Configuration.ORIENTATION_LANDSCAPE -> LANDSCAPE_MARGIN_HORIZONTAL
|
||||||
) {
|
else -> 0
|
||||||
LANDSCAPE_MARGIN_HORIZONTAL
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
listOf(binding.exoTopBar, binding.exoBottomBar).forEach {
|
listOf(binding.topBar, binding.bottomBar).forEach {
|
||||||
val params = it.layoutParams as MarginLayoutParams
|
val params = it.layoutParams as MarginLayoutParams
|
||||||
params.marginStart = newMargin
|
params.marginStart = newMargin
|
||||||
params.marginEnd = newMargin
|
params.marginEnd = newMargin
|
||||||
@ -574,7 +588,7 @@ internal class CustomExoPlayerView(
|
|||||||
/**
|
/**
|
||||||
* Load the captions style according to the users preferences
|
* Load the captions style according to the users preferences
|
||||||
*/
|
*/
|
||||||
fun applyCaptionsStyle() {
|
private fun applyCaptionsStyle() {
|
||||||
val captionStyle = PlayerHelper.getCaptionStyle(context)
|
val captionStyle = PlayerHelper.getCaptionStyle(context)
|
||||||
subtitleView?.apply {
|
subtitleView?.apply {
|
||||||
setApplyEmbeddedFontSizes(false)
|
setApplyEmbeddedFontSizes(false)
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
android:background="@color/exo_black_opacity_60" />
|
android:background="@color/exo_black_opacity_60" />
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/exo_top_bar"
|
android:id="@+id/top_bar"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="top"
|
android:layout_gravity="top"
|
||||||
@ -190,7 +190,7 @@
|
|||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@id/exo_bottom_bar"
|
android:id="@+id/bottom_bar"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="bottom"
|
android:layout_gravity="bottom"
|
||||||
@ -301,7 +301,7 @@
|
|||||||
android:layout_marginBottom="10dp">
|
android:layout_marginBottom="10dp">
|
||||||
|
|
||||||
<com.github.libretube.ui.views.MarkableTimeBar
|
<com.github.libretube.ui.views.MarkableTimeBar
|
||||||
android:id="@id/exo_progress"
|
android:id="@+id/exo_progress"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="16dp"
|
android:layout_height="16dp"
|
||||||
app:bar_height="2dp"
|
app:bar_height="2dp"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user