Skip to content

Commit

Permalink
feat: add long press for 2x speed (#596)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
peerless2012 and jarnedemeulemeester authored Jan 22, 2024
1 parent 060eab0 commit 0ecf6d4
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
31 changes: 31 additions & 0 deletions app/phone/src/main/res/layout/activity_player.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
27 changes: 27 additions & 0 deletions core/src/main/res/drawable/ic_speed_forward.xml
Original file line number Diff line number Diff line change
@@ -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>

0 comments on commit 0ecf6d4

Please sign in to comment.