Add Netflix-like seek animation

This commit is contained in:
Bnyro 2023-01-12 18:59:28 +01:00
parent 48776977ea
commit de02f75116
2 changed files with 44 additions and 11 deletions

View File

@ -259,9 +259,9 @@ internal class CustomExoPlayerView(
R.drawable.ic_speed, R.drawable.ic_speed,
{ {
"${ "${
player?.playbackParameters?.speed player?.playbackParameters?.speed
.toString() .toString()
.replace(".0", "") .replace(".0", "")
}x" }x"
} }
) { ) {
@ -366,17 +366,30 @@ internal class CustomExoPlayerView(
} }
} }
private fun animateSeeking(container: FrameLayout, imageView: ImageView, textView: TextView, isRewind: Boolean) { private fun animateSeeking(
container: FrameLayout,
imageView: ImageView,
textView: TextView,
isRewind: Boolean
) {
container.visibility = View.VISIBLE container.visibility = View.VISIBLE
// the direction of the action
val direction = if (isRewind) -1 else 1
// clear previous animation // clear previous animation
imageView.animate() imageView.animate()
.rotation(0F) .rotation(0F)
.setDuration(0) .setDuration(0)
.start() .start()
textView.animate()
.translationX(0f)
.setDuration(0)
.start()
// start the rotate animation of the drawable // start the rotate animation of the drawable
imageView.animate() imageView.animate()
.rotation(if (isRewind) -30F else 30F) .rotation(direction * 30F)
.setDuration(ANIMATION_DURATION) .setDuration(ANIMATION_DURATION)
.withEndAction { .withEndAction {
// reset the animation when finished // reset the animation when finished
@ -386,16 +399,30 @@ internal class CustomExoPlayerView(
.start() .start()
} }
.start() .start()
// animate the text view to move outside the image view
textView.animate()
.translationX(direction * 100f)
.setDuration((ANIMATION_DURATION * 1.5).toLong())
.withEndAction {
// move the text back into the button
handler.postDelayed({
textView.animate()
.setDuration(ANIMATION_DURATION / 2)
.translationX(0f)
.start()
}, 100)
}
} }
private val hideForwardButtonRunnable = Runnable { private val hideForwardButtonRunnable = Runnable {
doubleTapOverlayBinding?.forwardBTN.apply { doubleTapOverlayBinding?.forwardBTN?.apply {
this!!.visibility = View.GONE this.visibility = View.GONE
} }
} }
private val hideRewindButtonRunnable = Runnable { private val hideRewindButtonRunnable = Runnable {
doubleTapOverlayBinding?.rewindBTN.apply { doubleTapOverlayBinding?.rewindBTN?.apply {
this!!.visibility = View.GONE this.visibility = View.GONE
} }
} }

View File

@ -12,6 +12,8 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight=".40" android:layout_weight=".40"
android:clickable="false" android:clickable="false"
android:clipChildren="false"
android:clipToPadding="false"
android:focusable="false"> android:focusable="false">
<FrameLayout <FrameLayout
@ -33,7 +35,8 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center"
android:textColor="@android:color/white" /> android:textColor="@android:color/white"
android:translationZ="1dp" />
</FrameLayout> </FrameLayout>
@ -52,6 +55,8 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight=".40" android:layout_weight=".40"
android:clickable="false" android:clickable="false"
android:clipChildren="false"
android:clipToPadding="false"
android:focusable="false"> android:focusable="false">
<FrameLayout <FrameLayout
@ -73,7 +78,8 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center"
android:textColor="@android:color/white" /> android:textColor="@android:color/white"
android:translationZ="1dp" />
</FrameLayout> </FrameLayout>