feat: add long press for 2x speed (#596)
* Add long press for 2x speed. * Fix resource hard code warn. * Fix lint warn. * refactor: use `player.setPlaybackSpeed` * refactor: make playback speed increase easily adjustable later --------- Co-authored-by: jarnedemeulemeester <jarnedemeulemeester@gmail.com>
This commit is contained in:
parent
060eab0183
commit
0ecf6d4c0e
3 changed files with 78 additions and 0 deletions
|
@ -55,6 +55,9 @@ class PlayerGestureHelper(
|
|||
|
||||
private var lastScaleEvent: Long = 0
|
||||
|
||||
private var playbackSpeedIncrease: Float = 2f
|
||||
private var lastPlaybackSpeed: Float = 0f
|
||||
|
||||
private val screenWidth = Resources.getSystem().displayMetrics.widthPixels
|
||||
private val screenHeight = Resources.getSystem().displayMetrics.heightPixels
|
||||
|
||||
|
@ -69,6 +72,18 @@ class PlayerGestureHelper(
|
|||
return true
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
override fun onLongPress(e: MotionEvent) {
|
||||
playerView.player?.let {
|
||||
if (it.isPlaying) {
|
||||
lastPlaybackSpeed = it.playbackParameters.speed
|
||||
it.setPlaybackSpeed(playbackSpeedIncrease)
|
||||
activity.binding.gestureSpeedText.text = playbackSpeedIncrease.toString() + "x"
|
||||
activity.binding.gestureSpeedLayout.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDoubleTap(e: MotionEvent): Boolean {
|
||||
// Disables double tap gestures if view is locked
|
||||
if (isControlsLocked) return false
|
||||
|
@ -362,6 +377,11 @@ class PlayerGestureHelper(
|
|||
}
|
||||
}
|
||||
}
|
||||
if (lastPlaybackSpeed > 0 && (event.action == MotionEvent.ACTION_UP || event.action == MotionEvent.ACTION_CANCEL)) {
|
||||
playerView.player?.setPlaybackSpeed(lastPlaybackSpeed)
|
||||
lastPlaybackSpeed = 0f
|
||||
activity.binding.gestureSpeedLayout.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
private fun longToTimestamp(duration: Long, noSign: Boolean = false): String {
|
||||
|
|
|
@ -113,6 +113,37 @@
|
|||
tools:ignore="ContentDescription" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/gesture_speed_layout"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="64dp"
|
||||
android:layout_gravity="center_horizontal|top"
|
||||
android:layout_margin="16dp"
|
||||
android:background="@drawable/overlay_background"
|
||||
android:clickable="false"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/gesture_speed_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:gravity="center"
|
||||
android:textSize="20sp"
|
||||
android:textColor="@android:color/white" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/gesture_speed_image"
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_marginHorizontal="16dp"
|
||||
android:src="@drawable/ic_speed_forward"
|
||||
tools:ignore="ContentDescription" />
|
||||
</LinearLayout>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/image_ffwd_animation_ripple"
|
||||
android:layout_width="50dp"
|
||||
|
|
27
core/src/main/res/drawable/ic_speed_forward.xml
Normal file
27
core/src/main/res/drawable/ic_speed_forward.xml
Normal file
|
@ -0,0 +1,27 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="36dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="36"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:pathData="M14,19l9,-7l-9,-7l0,14z"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="2"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="@android:color/white"
|
||||
android:strokeLineCap="round"/>
|
||||
<path
|
||||
android:pathData="M2,19l9,-7l-9,-7l0,14z"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="2"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="@android:color/white"
|
||||
android:strokeLineCap="round"/>
|
||||
<path
|
||||
android:pathData="M26,19l9,-7l-9,-7l0,14z"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="2"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="@android:color/white"
|
||||
android:strokeLineCap="round"/>
|
||||
</vector>
|
Loading…
Reference in a new issue