Skip to content

Allow to choose max playback speed in settings to your liking #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: extended
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -178,14 +171,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(
Expand Down Expand Up @@ -217,13 +213,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(
Expand Down Expand Up @@ -489,6 +485,12 @@ 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
Expand Down Expand Up @@ -528,16 +530,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,
Expand All @@ -548,7 +552,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;
Expand Down Expand Up @@ -613,8 +618,10 @@ 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ public static String getActionForLeftGestureSide(@NonNull final Context context)
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);
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@
<string name="popup_remember_size_pos_title">Eigenschaften des Pop-ups merken</string>
<string name="use_external_video_player_summary">Entfernt Tonspur bei manchen Auflösungen</string>
<string name="popup_remember_size_pos_summary">Letzte Größe und Position des Pop-ups merken</string>
<string name="max_playback_speed_title">Maximale Geschwindigkeit (E)</string>
<string name="max_playback_speed_summary">Maximale Wiedergabegeschwindigkeit festlegen</string>
<string name="show_search_suggestions_title">Suchvorschläge</string>
<string name="show_search_suggestions_summary">Vorschläge auswählen, die bei der Suche angezeigt werden sollen</string>
<string name="clear">löschen</string>
Expand Down
20 changes: 18 additions & 2 deletions app/src/main/res/values/settings_keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,13 @@
<item>@string/audio_webm_key</item>
</string-array>

<string name="left_gesture_control_key">left_gesture_control</string>
<string name="default_left_gesture_control_value">@string/brightness_control_key</string>
<string name="brightness_control_key">brightness_control</string>
<string name="volume_control_key">volume_control</string>
<string name="playback_speed_control_key">playback_speed_control</string>
<string name="none_control_key">none_control</string>

<string name="left_gesture_control_key">left_gesture_control</string>
<string name="default_left_gesture_control_value">@string/brightness_control_key</string>
<string-array name="left_gesture_control_description">
<item>@string/brightness</item>
<item>@string/volume</item>
Expand Down Expand Up @@ -249,6 +250,21 @@
<item>@string/none_control_key</item>
</string-array>

<string name="max_playback_speed_key">max_playback_speed</string>
<string name="default_max_playback_speed_value">3</string>
<string-array name="max_playback_speed_description">
<item>2x</item>
<item>3x</item>
<item>5x</item>
<item>10x</item>
</string-array>
<string-array name="max_playback_speed_values">
<item>2</item>
<item>3</item>
<item>5</item>
<item>10</item>
</string-array>

<string name="prefer_original_audio_key">prefer_original_audio</string>
<string name="prefer_descriptive_audio_key">prefer_descriptive_audio</string>
<string name="last_resize_mode">last_resize_mode</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@
<string name="brightness">Brightness</string>
<string name="volume">Volume</string>
<string name="none">None</string>
<string name="max_playback_speed_title">Maximum playback speed (E)</string>
<string name="max_playback_speed_summary">Choose the maximum playback speed</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
10 changes: 10 additions & 0 deletions app/src/main/res/xml/video_audio_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,16 @@
app:singleLineTitle="false"
app:iconSpaceReserved="false" />

<ListPreference
android:defaultValue="@string/default_max_playback_speed_value"
android:entries="@array/max_playback_speed_description"
android:entryValues="@array/max_playback_speed_values"
android:key="@string/max_playback_speed_key"
android:summary="@string/max_playback_speed_summary"
android:title="@string/max_playback_speed_title"
app:singleLineTitle="false"
app:iconSpaceReserved="false" />

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