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 f96713633..8f36e5eb6 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 a47a1cd46..5f3d491d1 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,8 +45,6 @@ public class PlaybackParameterDialog extends DialogFragment { // Minimum allowable range in ExoPlayer private static final double MIN_PITCH_OR_SPEED = 0.10f; - 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; @@ -61,12 +59,6 @@ public class PlaybackParameterDialog extends DialogFragment { private static final double DEFAULT_STEP = STEP_25_PERCENT_VALUE; private static final boolean DEFAULT_SKIP_SILENCE = false; private static final boolean DEFAULT_PLAYBACK_UNHOOK = false; - 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) { @@ -177,14 +169,17 @@ public Dialog onCreateDialog(@Nullable final Bundle savedInstanceState) { private void initUI() { // Tempo + final float maxPitchOrSpeed = getMaxPitchOrSpeed(requireContext()); + final SliderStrategy quadraticStrategy = getQuadraticStrategy(requireContext()); + setText(binding.tempoMinimumText, PlayerHelper::formatSpeed, MIN_PITCH_OR_SPEED); - setText(binding.tempoMaximumText, PlayerHelper::formatSpeed, MAX_PITCH_OR_SPEED); + setText(binding.tempoMaximumText, PlayerHelper::formatSpeed, maxPitchOrSpeed); - binding.tempoSeekbar.setMax(QUADRATIC_STRATEGY.progressOf(MAX_PITCH_OR_SPEED)); + binding.tempoSeekbar.setMax(quadraticStrategy.progressOf(maxPitchOrSpeed)); setAndUpdateTempo(tempo); binding.tempoSeekbar.setOnSeekBarChangeListener( getTempoOrPitchSeekbarChangeListener( - QUADRATIC_STRATEGY, + quadraticStrategy, this::onTempoSliderUpdated)); registerOnStepClickListener( @@ -216,13 +211,13 @@ private void initUI() { // 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( @@ -488,6 +483,13 @@ private void ensureHookIsValidAndUpdateCallBack() { // 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 @@ -527,16 +529,18 @@ private void setSliders(final double newValue) { } 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, @@ -547,7 +551,8 @@ private void setAndUpdatePitch(final double newPitch) { } 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; @@ -612,11 +617,13 @@ public static float getMinPitchOrSpeed() { 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 { + public interface Callback { void onPlaybackParameterChanged(float playbackTempo, float playbackPitch, boolean playbackSkipSilence); } diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 13f55b997..2deb7d6d6 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -102,6 +102,8 @@ Eigenschaften des Pop-ups merken Entfernt Tonspur bei manchen Auflösungen Letzte Größe und Position des Pop-ups merken + Maximale Geschwindigkeit + Maximale Wiedergabegeschwindigkeit festlegen Suchvorschläge Vorschläge auswählen, die bei der Suche angezeigt werden sollen löschen diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index 41de40e20..96fbdd197 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -200,12 +200,13 @@ @string/audio_webm_key - left_gesture_control - @string/brightness_control_key brightness_control volume_control playback_speed_control none_control + + left_gesture_control + @string/brightness_control_key @string/brightness @string/volume @@ -249,6 +250,21 @@ @string/none_control_key + max_playback_speed + 5 + + 2x + 3x + 5x + 10x + + + 2 + 3 + 5 + 10 + + prefer_original_audio prefer_descriptive_audio last_resize_mode diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c1944dda1..122a899f5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -116,6 +116,8 @@ Brightness Volume None + Maximum playback speed + Choose the maximum playback speed Search suggestions Choose the suggestions to show when searching Local search suggestions diff --git a/app/src/main/res/xml/video_audio_settings.xml b/app/src/main/res/xml/video_audio_settings.xml index 3d13e0b71..587501a19 100644 --- a/app/src/main/res/xml/video_audio_settings.xml +++ b/app/src/main/res/xml/video_audio_settings.xml @@ -218,6 +218,16 @@ app:singleLineTitle="false" app:iconSpaceReserved="false" /> + +