Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/src/main/java/org/schabi/newpipe/player/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -5493,6 +5493,10 @@ public TextView getSwipeSeekDisplay() {
return binding.swipeSeekDisplay;
}

public TextView getSwipeSpeedDisplay() {
return binding.swipeSpeedDisplay;
}

public PlayerFastSeekOverlay getFastSeekOverlay() {
return binding.fastSeekOverlay;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ abstract class BasePlayerGestureListener(

// Check if swiping up (negative y velocity)
if (yVelocity < 0) {
v.parent.requestDisallowInterceptTouchEvent(player.isFullscreenGestureEnabled || player.isFullscreen)
v.parent.requestDisallowInterceptTouchEvent(
player.isFullscreenGestureEnabled
|| player.isFullscreen
|| PlayerHelper.isPlaybackSpeedGestureEnabled(service)
)
} else {
v.parent.requestDisallowInterceptTouchEvent(player.isFullscreen)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import static org.schabi.newpipe.player.Player.DEFAULT_CONTROLS_HIDE_TIME;
import static org.schabi.newpipe.player.Player.STATE_PLAYING;

import java.util.Locale;

import android.app.Activity;
import android.util.Log;
import android.view.MotionEvent;
Expand Down Expand Up @@ -49,6 +51,12 @@ public class PlayerGestureListener
private long swipeSeekTargetPosition = 0L;
private boolean isChangingVolume = false;
private boolean isChangingBrightness = false;
private boolean isChangingSpeed = false;
private float speedGestureStartSpeed = 1.0f;
private float accumulatedSpeedScroll = 0f;
private static final float SPEED_SWIPE_PIXELS_PER_STEP = 20f;
private static final float SPEED_MIN = 0.1f;
private static final float SPEED_MAX = 4.0f;

private boolean isPendingScreenRotation = false;
private boolean isFullscreenRotationGesture = false;
Expand Down Expand Up @@ -127,6 +135,11 @@ public void onScroll(@NonNull final PlayerService.PlayerType playerType,
return;
}

if (isChangingSpeed) {
onScrollMainSpeed(distanceY);
return;
}

final boolean isHorizontal = Math.abs(distanceX) > Math.abs(distanceY);
if (!isHorizontal && isFullscreenGestureEnabled &&
((player.isFullscreen() && distanceY < 0 && portion == DisplayPortion.MIDDLE) ||
Expand All @@ -139,6 +152,15 @@ public void onScroll(@NonNull final PlayerService.PlayerType playerType,
if(!player.isFullscreen()) {
return;
}

final boolean isPlaybackSpeedGestureEnabled =
PlayerHelper.isPlaybackSpeedGestureEnabled(service);
if (!isHorizontal && isPlaybackSpeedGestureEnabled && player.isFullscreen()
&& portion == DisplayPortion.MIDDLE) {
onScrollMainSpeed(distanceY);
return;
}

if (isSwipeSeekGestureEnabled && isHorizontal) {
onScrollMainSeek(distanceX);
return;
Expand Down Expand Up @@ -258,6 +280,31 @@ private void onScrollMainBrightness(final float distanceX, final float distanceY
}
}

private void onScrollMainSpeed(final float distanceY) {
if (!isChangingSpeed) {
isChangingSpeed = true;
accumulatedSpeedScroll = 0f;
speedGestureStartSpeed = player.getPlaybackSpeed();
animate(player.getSwipeSpeedDisplay(), true, DEFAULT_CONTROLS_DURATION, SCALE_AND_ALPHA);
if (player.getVolumeRelativeLayout().getVisibility() == View.VISIBLE) {
animate(player.getVolumeRelativeLayout(), false, 200, SCALE_AND_ALPHA);
isChangingVolume = false;
}
if (player.getBrightnessRelativeLayout().getVisibility() == View.VISIBLE) {
animate(player.getBrightnessRelativeLayout(), false, 200, SCALE_AND_ALPHA);
isChangingBrightness = false;
}
}

accumulatedSpeedScroll += distanceY; // positive = swipe up = faster
final float rawSpeed = speedGestureStartSpeed
+ (accumulatedSpeedScroll / SPEED_SWIPE_PIXELS_PER_STEP) * 0.1f;
final float speed = Math.max(SPEED_MIN, Math.min(SPEED_MAX,
Math.round(rawSpeed * 10) / 10.0f));
player.setPlaybackSpeed(speed);
player.getSwipeSpeedDisplay().setText(String.format(Locale.getDefault(), "%.1fx", speed));
}

private void onScrollMainSeek(final float distanceX) {
// The first swipe determines the active overlay; once seeking is engaged
// we hide volume and brightness controls so mixed movements do not trigger them.
Expand Down Expand Up @@ -327,6 +374,10 @@ public void onScrollEnd(@NonNull final PlayerService.PlayerType playerType,
animate(player.getSwipeSeekDisplay(), false, 200, SCALE_AND_ALPHA);
isSwipeSeeking = false;
}
if (isChangingSpeed) {
animate(player.getSwipeSpeedDisplay(), false, 200, SCALE_AND_ALPHA, 200);
isChangingSpeed = false;
}
if (player.getVolumeRelativeLayout().getVisibility() == View.VISIBLE) {
animate(player.getVolumeRelativeLayout(), false, 200, SCALE_AND_ALPHA,
200);
Expand Down Expand Up @@ -357,10 +408,12 @@ public void onPopupResizingStart() {
player.hideControls(0, 0);
animate(player.getFastSeekOverlay(), false, 0);
animate(player.getSwipeSeekDisplay(), false, 0, ALPHA, 0);
animate(player.getSwipeSpeedDisplay(), false, 0, ALPHA, 0);
animate(player.getVolumeRelativeLayout(), false, 0, ALPHA, 0);
animate(player.getBrightnessRelativeLayout(), false, 0, ALPHA, 0);
isChangingVolume = false;
isChangingBrightness = false;
isChangingSpeed = false;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,11 @@ public static boolean isSwipeSeekGestureEnabled(@NonNull final Context context)
.getBoolean(context.getString(R.string.swipe_seek_gesture_control_key), true);
}

public static boolean isPlaybackSpeedGestureEnabled(@NonNull final Context context) {
return getPreferences(context)
.getBoolean(context.getString(R.string.playback_speed_gesture_control_key), false);
}

public static boolean isStartMainPlayerFullscreenEnabled(@NonNull final Context context) {
return getPreferences(context)
.getBoolean(context.getString(R.string.start_main_player_fullscreen_key), false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import androidx.annotation.Nullable;
import androidx.preference.ListPreference;
import androidx.preference.SwitchPreferenceCompat;

import org.schabi.newpipe.R;

Expand All @@ -19,6 +20,32 @@ public void onCreatePreferences(@Nullable final Bundle savedInstanceState,
@Nullable final String rootKey) {
addPreferencesFromResourceRegistry();
updateSeekOptions();
setupSpeedGestureMutualExclusion();
}

private void setupSpeedGestureMutualExclusion() {
final SwitchPreferenceCompat fullscreenPref = findPreference(
getString(R.string.fullscreen_gesture_control_key));
final SwitchPreferenceCompat speedPref = findPreference(
getString(R.string.playback_speed_gesture_control_key));

if (fullscreenPref == null || speedPref == null) {
return;
}

fullscreenPref.setOnPreferenceChangeListener((pref, newValue) -> {
if (Boolean.TRUE.equals(newValue)) {
speedPref.setChecked(false);
}
return true;
});

speedPref.setOnPreferenceChangeListener((pref, newValue) -> {
if (Boolean.TRUE.equals(newValue)) {
fullscreenPref.setChecked(false);
}
return true;
});
}

private void updateSeekOptions() {
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/res/layout/player.xml
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,20 @@
tools:ignore="RtlHardcoded"
tools:text="+0:00 (0:00)" />

<org.schabi.newpipe.views.NewPipeTextView
android:id="@+id/swipeSpeedDisplay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@drawable/background_rectangle_black_transparent"
android:padding="8dp"
android:textColor="@android:color/white"
android:textSize="22sp"
android:textStyle="bold"
android:visibility="gone"
tools:ignore="RtlHardcoded"
tools:text="1.0x" />

<org.schabi.newpipe.views.BulletCommentsView
android:id="@+id/bulletCommentsView"
android:layout_width="match_parent"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/settings_keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<string name="brightness_gesture_control_key">brightness_gesture_control</string>
<string name="fullscreen_gesture_control_key">fullscreen_gesture_control</string>
<string name="swipe_seek_gesture_control_key">swipe_seek_gesture_control</string>
<string name="playback_speed_gesture_control_key">playback_speed_gesture_control</string>
<string name="resume_on_audio_focus_gain_key">resume_on_audio_focus_gain</string>
<string name="popup_remember_size_pos_key">popup_remember_size_pos_key</string>
<string name="use_inexact_seek_key">use_inexact_seek_key</string>
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@
<string name="brightness_gesture_control_summary">Use gestures to control player brightness</string>
<string name="swipe_seek_gesture_control_title">Swipe to seek gesture</string>
<string name="swipe_seek_gesture_control_summary">Swipe right to fast-forward, and left to rewind</string>
<string name="playback_speed_gesture_control_title">Swipe to control playback speed</string>
<string name="playback_speed_gesture_control_summary">Use gestures to control playback speed. Disables fullscreen gesture control</string>
<string name="show_search_suggestions_title">Search suggestions</string>
<string name="show_search_suggestions_summary">Choose the suggestions to show when searching</string>
<string name="local_search_suggestions">Local search suggestions</string>
Expand Down Expand Up @@ -922,7 +924,7 @@
<string name="view_on_github">View on GitHub</string>
<string name="donation_dialog_title">Support the Project</string>
<string name="donation_dialog_message">Thank you for using PipePipe! If you find it useful, please consider becoming a supporter on Ko-Fi. Your support is important to me and helps me add more exciting new features. Every bit counts! 😇</string>
<string name="fullscreen_gesture_control_summary">Use gestures to enter / exit fullscreen</string>
<string name="fullscreen_gesture_control_summary">Use gestures to enter / exit fullscreen. Disables playback speed gesture control</string>
<string name="fullscreen_gesture_control_title">Fullscreen gesture control</string>
<string name="require_audio_focus_summary">Make sure only PipePipe is playing audio</string>
<string name="require_audio_focus_title">Require audio focus</string>
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/xml/gesture_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@
app:singleLineTitle="false"
app:iconSpaceReserved="false" />

<SwitchPreferenceCompat
android:defaultValue="false"
android:key="@string/playback_speed_gesture_control_key"
android:summary="@string/playback_speed_gesture_control_summary"
android:title="@string/playback_speed_gesture_control_title"
app:singleLineTitle="false"
app:iconSpaceReserved="false" />

<SwitchPreferenceCompat
android:defaultValue="true"
android:key="@string/swipe_seek_gesture_control_key"
Expand Down