@@ -9,6 +9,7 @@ import android.view.View
99import androidx.core.os.postDelayed
1010import org.schabi.newpipe.databinding.PlayerBinding
1111import org.schabi.newpipe.player.Player
12+ import org.schabi.newpipe.player.helper.PlayerHelper
1213import org.schabi.newpipe.player.ui.VideoPlayerUi
1314
1415/* *
@@ -24,8 +25,59 @@ abstract class BasePlayerGestureListener(
2425 protected val player: Player = playerUi.player
2526 protected val binding: PlayerBinding = playerUi.binding
2627
28+ // ///////////////////////////////////////////////////////////////////
29+ // Long press (hold) to fast-forward
30+ // ///////////////////////////////////////////////////////////////////
31+
32+ private var isHoldingForFastForward = false
33+ private var originalPlaybackSpeed = 1.0f
34+ private val longPressHandler: Handler = Handler (Looper .getMainLooper())
35+ private val longPressRunnable = Runnable {
36+ if (PlayerHelper .isHoldToFastForwardEnabled(player.context) &&
37+ player.currentState == Player .STATE_PLAYING &&
38+ ! playerUi.isSomePopupMenuVisible
39+ ) {
40+ startFastForward()
41+ }
42+ }
43+
44+ private fun startFastForward () {
45+ if (! isHoldingForFastForward) {
46+ if (DEBUG ) {
47+ Log .d(TAG , " startFastForward called" )
48+ }
49+ isHoldingForFastForward = true
50+ originalPlaybackSpeed = player.playbackSpeed
51+ player.setPlaybackSpeed(2.0f )
52+ }
53+ }
54+
55+ private fun stopFastForward () {
56+ if (isHoldingForFastForward) {
57+ if (DEBUG ) {
58+ Log .d(TAG , " stopFastForward called, restoring speed to $originalPlaybackSpeed " )
59+ }
60+ isHoldingForFastForward = false
61+ player.setPlaybackSpeed(originalPlaybackSpeed)
62+ }
63+ longPressHandler.removeCallbacks(longPressRunnable)
64+ }
65+
2766 override fun onTouch (v : View , event : MotionEvent ): Boolean {
2867 playerUi.gestureDetector.onTouchEvent(event)
68+
69+ // Handle long press for fast-forward
70+ when (event.action) {
71+ MotionEvent .ACTION_DOWN -> {
72+ // Start timer for long press detection
73+ longPressHandler.postDelayed(longPressRunnable, LONG_PRESS_DELAY )
74+ }
75+ MotionEvent .ACTION_UP , MotionEvent .ACTION_CANCEL -> {
76+ // Stop fast-forward when finger is lifted
77+ stopFastForward()
78+ }
79+ }
80+
2981 return false
3082 }
3183
@@ -184,5 +236,6 @@ abstract class BasePlayerGestureListener(
184236
185237 private const val DOUBLE_TAP = " doubleTap"
186238 private const val DOUBLE_TAP_DELAY = 550L
239+ private const val LONG_PRESS_DELAY = 500L
187240 }
188241}
0 commit comments