@@ -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,11 +25,87 @@ abstract class BasePlayerGestureListener(
2425 protected val player: Player = playerUi.player
2526 protected val binding: PlayerBinding = playerUi.binding
2627
28+ // ///////////////////////////////////////////////////////////////////
29+ // Hold to fast forward (2x speed)
30+ // ///////////////////////////////////////////////////////////////////
31+
32+ private var isHoldingForFastForward = false
33+ private var originalPlaybackSpeed = 1.0f
34+ private val fastForwardSpeed = 2.0f
35+
2736 override fun onTouch (v : View , event : MotionEvent ): Boolean {
2837 playerUi.gestureDetector.onTouchEvent(event)
38+
39+ // Handle touch up to restore original speed when hold-to-fast-forward is active
40+ if (event.action == MotionEvent .ACTION_UP || event.action == MotionEvent .ACTION_CANCEL ) {
41+ if (isHoldingForFastForward) {
42+ stopHoldToFastForward()
43+ }
44+ }
45+
2946 return false
3047 }
3148
49+ override fun onLongPress (e : MotionEvent ) {
50+ if (DEBUG ) {
51+ Log .d(TAG , " onLongPress called with e = [$e ]" )
52+ }
53+
54+ // Check if hold-to-fast-forward is enabled in settings
55+ if (! PlayerHelper .isHoldToFastForwardEnabled(player.context)) {
56+ return
57+ }
58+
59+ // Only activate if player is playing and not in a popup menu
60+ if (player.currentState != Player .STATE_PLAYING || playerUi.isSomePopupMenuVisible) {
61+ return
62+ }
63+
64+ // Don't activate during double tap mode
65+ if (isDoubleTapping) {
66+ return
67+ }
68+
69+ startHoldToFastForward()
70+ }
71+
72+ private fun startHoldToFastForward () {
73+ if (isHoldingForFastForward) {
74+ return
75+ }
76+
77+ if (DEBUG ) {
78+ Log .d(TAG , " startHoldToFastForward: activating 2x speed" )
79+ }
80+
81+ isHoldingForFastForward = true
82+ originalPlaybackSpeed = player.playbackSpeed
83+
84+ // Set playback speed to 2x
85+ player.setPlaybackSpeed(fastForwardSpeed)
86+
87+ // Show visual feedback
88+ playerUi.onHoldToFastForwardStart()
89+ }
90+
91+ private fun stopHoldToFastForward () {
92+ if (! isHoldingForFastForward) {
93+ return
94+ }
95+
96+ if (DEBUG ) {
97+ Log .d(TAG , " stopHoldToFastForward: restoring original speed $originalPlaybackSpeed " )
98+ }
99+
100+ isHoldingForFastForward = false
101+
102+ // Restore original playback speed
103+ player.setPlaybackSpeed(originalPlaybackSpeed)
104+
105+ // Hide visual feedback
106+ playerUi.onHoldToFastForwardEnd()
107+ }
108+
32109 private fun onDoubleTap (
33110 event : MotionEvent ,
34111 portion : DisplayPortion
0 commit comments