From b28175c0f13744cab38bce201594802ba48b46ce Mon Sep 17 00:00:00 2001 From: klaviartur <_github@fambit.de> Date: Wed, 12 Feb 2025 14:32:42 +0100 Subject: [PATCH] follow max playback speed setting in main player --- .../gesture/MainPlayerGestureListener.kt | 2 +- .../helper/PlaybackParameterDialog.java | 47 +++++++++++-------- .../newpipe/player/helper/PlayerHelper.java | 1 + 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/gesture/MainPlayerGestureListener.kt b/app/src/main/java/org/schabi/newpipe/player/gesture/MainPlayerGestureListener.kt index e33b393ad..a2317031a 100644 --- a/app/src/main/java/org/schabi/newpipe/player/gesture/MainPlayerGestureListener.kt +++ b/app/src/main/java/org/schabi/newpipe/player/gesture/MainPlayerGestureListener.kt @@ -156,7 +156,7 @@ class MainPlayerGestureListener( private fun onScrollPlaybackSpeed(distanceY: Float) { val bar: ProgressBar = binding.playbackSpeedProgressBar - val maxPlaybackSpeed: Float = PlaybackParameterDialog.getMaxPitchOrSpeed() + val maxPlaybackSpeed: Float = PlaybackParameterDialog.getMaxPitchOrSpeed(player.context) val minPlaybackSpeed: Float = PlaybackParameterDialog.getMinPitchOrSpeed() val playbackSpeedStep: Float = PlaybackParameterDialog.getCurrentStepSize(player.context) / maxPlaybackSpeed diff --git a/app/src/main/java/org/schabi/newpipe/player/helper/PlaybackParameterDialog.java b/app/src/main/java/org/schabi/newpipe/player/helper/PlaybackParameterDialog.java index d6ca85d16..80df2e617 100644 --- a/app/src/main/java/org/schabi/newpipe/player/helper/PlaybackParameterDialog.java +++ b/app/src/main/java/org/schabi/newpipe/player/helper/PlaybackParameterDialog.java @@ -45,7 +45,6 @@ public class PlaybackParameterDialog extends DialogFragment { // Minimum allowable range in ExoPlayer private static final double MIN_PITCH_OR_SPEED = 0.1f; - private static final double MAX_PITCH_OR_SPEED = 5.00f; private static final boolean PITCH_CTRL_MODE_PERCENT = false; private static final boolean PITCH_CTRL_MODE_SEMITONE = true; @@ -62,12 +61,6 @@ public class PlaybackParameterDialog extends DialogFragment { private static final boolean DEFAULT_SKIP_SILENCE = false; private static final boolean DEFAULT_PLAYBACK_UNHOOK = true; - private static final SliderStrategy QUADRATIC_STRATEGY = new SliderStrategy.Quadratic( - MIN_PITCH_OR_SPEED, - MAX_PITCH_OR_SPEED, - 1.00f, - 10_000); - private static final SliderStrategy SEMITONE_STRATEGY = new SliderStrategy() { @Override public int progressOf(final double value) { @@ -178,14 +171,17 @@ public class PlaybackParameterDialog extends DialogFragment { private void initUI() { // Tempo - setText(binding.tempoMinimumText, PlayerHelper::formatSpeed, MIN_PITCH_OR_SPEED); - setText(binding.tempoMaximumText, PlayerHelper::formatSpeed, MAX_PITCH_OR_SPEED); + final float maxPitchOrSpeed = getMaxPitchOrSpeed(requireContext()); + final SliderStrategy quadraticStrategy = getQuadraticStrategy(requireContext()); - binding.tempoSeekbar.setMax(QUADRATIC_STRATEGY.progressOf(MAX_PITCH_OR_SPEED)); + setText(binding.tempoMinimumText, PlayerHelper::formatSpeed, MIN_PITCH_OR_SPEED); + setText(binding.tempoMaximumText, PlayerHelper::formatSpeed, maxPitchOrSpeed); + + binding.tempoSeekbar.setMax(quadraticStrategy.progressOf(maxPitchOrSpeed)); setAndUpdateTempo(tempo); binding.tempoSeekbar.setOnSeekBarChangeListener( getTempoOrPitchSeekbarChangeListener( - QUADRATIC_STRATEGY, + quadraticStrategy, this::onTempoSliderUpdated)); registerOnStepClickListener( @@ -217,13 +213,13 @@ public class PlaybackParameterDialog extends DialogFragment { // Pitch - Percent setText(binding.pitchPercentMinimumText, PlayerHelper::formatPitch, MIN_PITCH_OR_SPEED); - setText(binding.pitchPercentMaximumText, PlayerHelper::formatPitch, MAX_PITCH_OR_SPEED); + setText(binding.pitchPercentMaximumText, PlayerHelper::formatPitch, maxPitchOrSpeed); - binding.pitchPercentSeekbar.setMax(QUADRATIC_STRATEGY.progressOf(MAX_PITCH_OR_SPEED)); + binding.pitchPercentSeekbar.setMax(quadraticStrategy.progressOf(maxPitchOrSpeed)); setAndUpdatePitch(pitchPercent); binding.pitchPercentSeekbar.setOnSeekBarChangeListener( getTempoOrPitchSeekbarChangeListener( - QUADRATIC_STRATEGY, + quadraticStrategy, this::onPitchPercentSliderUpdated)); registerOnStepClickListener( @@ -489,6 +485,12 @@ public class PlaybackParameterDialog extends DialogFragment { // Sliders //////////////////////////////////////////////////////////////////////////*/ + private SliderStrategy getQuadraticStrategy(final Context context) { + return new SliderStrategy.Quadratic( + MIN_PITCH_OR_SPEED, getMaxPitchOrSpeed(context), + 1.00f, + 10_000); + } private SeekBar.OnSeekBarChangeListener getTempoOrPitchSeekbarChangeListener( final SliderStrategy sliderStrategy, final DoubleConsumer newValueConsumer @@ -528,16 +530,18 @@ public class PlaybackParameterDialog extends DialogFragment { } private void setAndUpdateTempo(final double newTempo) { - this.tempo = MathUtils.clamp(newTempo, MIN_PITCH_OR_SPEED, MAX_PITCH_OR_SPEED); + this.tempo = MathUtils.clamp(newTempo, MIN_PITCH_OR_SPEED, + getMaxPitchOrSpeed(requireContext())); - binding.tempoSeekbar.setProgress(QUADRATIC_STRATEGY.progressOf(tempo)); + binding.tempoSeekbar.setProgress(getQuadraticStrategy(requireContext()).progressOf(tempo)); setText(binding.tempoCurrentText, PlayerHelper::formatSpeed, tempo); } private void setAndUpdatePitch(final double newPitch) { this.pitchPercent = calcValidPitch(newPitch); - binding.pitchPercentSeekbar.setProgress(QUADRATIC_STRATEGY.progressOf(pitchPercent)); + binding.pitchPercentSeekbar.setProgress(getQuadraticStrategy(requireContext()) + .progressOf(pitchPercent)); binding.pitchSemitoneSeekbar.setProgress(SEMITONE_STRATEGY.progressOf(pitchPercent)); setText(binding.pitchPercentCurrentText, PlayerHelper::formatPitch, @@ -548,7 +552,8 @@ public class PlaybackParameterDialog extends DialogFragment { } private double calcValidPitch(final double newPitch) { - final double calcPitch = MathUtils.clamp(newPitch, MIN_PITCH_OR_SPEED, MAX_PITCH_OR_SPEED); + final double calcPitch = MathUtils.clamp(newPitch, MIN_PITCH_OR_SPEED, + getMaxPitchOrSpeed(requireContext())); if (!isCurrentPitchControlModeSemitone()) { return calcPitch; @@ -613,8 +618,10 @@ public class PlaybackParameterDialog extends DialogFragment { return (float) MIN_PITCH_OR_SPEED; } - public static float getMaxPitchOrSpeed() { - return (float) MAX_PITCH_OR_SPEED; + public static float getMaxPitchOrSpeed(final Context context) { + return Float.parseFloat(PreferenceManager.getDefaultSharedPreferences(context) + .getString(context.getString(R.string.max_playback_speed_key), + context.getString(R.string.default_max_playback_speed_value))); } public interface Callback { diff --git a/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java b/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java index 6a51bdbea..9587854b3 100644 --- a/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java +++ b/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java @@ -246,6 +246,7 @@ public final class PlayerHelper { context.getString(R.string.default_left_gesture_control_value)); } + public static boolean isStartMainPlayerFullscreenEnabled(@NonNull final Context context) { return getPreferences(context) .getBoolean(context.getString(R.string.start_main_player_fullscreen_key), false);