Skip to content

Commit

Permalink
Ensure backwards compatibility to versions with speed vals from 5-25
Browse files Browse the repository at this point in the history
  • Loading branch information
flackbash committed May 1, 2021
1 parent ca908ce commit 4005007
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -832,12 +832,24 @@ void showPlaybackSpeedDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
final View dialogView = this.getLayoutInflater().inflate(R.layout.dialog_playback_speed, null);
builder.setView(dialogView);
builder.setTitle(R.string.playback_speed);

final TextView playbackSpeedTV = dialogView.findViewById(R.id.playback_speed_tv);
SeekBar playbackSpeedSB = dialogView.findViewById(R.id.playback_speed_sb);
float normalSpeed = Integer.parseInt(getString(R.string.preference_playback_speed_default));
int minSpeed = Integer.parseInt(getString(R.string.preference_playback_speed_minimum));;
playbackSpeedSB.setMax((int)(2.5 * normalSpeed)); // min + max = 0.5 + 2.5 = 3.0 --> max playback speed 3.0
int currSpeed = mSharedPreferences.getInt(getString(R.string.preference_playback_speed_key), Integer.parseInt(getString(R.string.preference_playback_speed_default)));
if (currSpeed < minSpeed) {
// Ensure backwards compatibility where stored speed was in range 5 - 25
currSpeed = currSpeed * 10;
// Store new playback speed in shared preferences
SharedPreferences.Editor editor = mSharedPreferences.edit();
editor.putInt(getString(R.string.preference_playback_speed_key), currSpeed);
editor.apply();
}
float currSpeedFloat = currSpeed / normalSpeed;
playbackSpeedTV.setText(getString(R.string.playback_speed_label, currSpeedFloat));
int progress = getProgressFromPlaybackSpeed(currSpeed);
playbackSpeedSB.setProgress(progress);
playbackSpeedSB.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
Expand Down Expand Up @@ -891,13 +903,6 @@ public void onStopTrackingTouch(SeekBar seekBar) {
}
});

builder.setTitle(R.string.playback_speed);

// Set the text of the TextView to the default speed
int speed = mSharedPreferences.getInt(getString(R.string.preference_playback_speed_key), Integer.parseInt(getString(R.string.preference_playback_speed_default)));
float speedFloat = speed / normalSpeed;
playbackSpeedTV.setText(getString(R.string.playback_speed_label, speedFloat));

// Create and show the AlertDialog
AlertDialog alertDialog = builder.create();
alertDialog.show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,15 @@ void initMediaPlayer(String path, int position) {
// Set playback speed according to preferences
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
int speed = mSharedPreferences.getInt(getString(R.string.preference_playback_speed_key), Integer.parseInt(getString(R.string.preference_playback_speed_default)));
int minSpeed = Integer.parseInt(getString(R.string.preference_playback_speed_minimum));;
if (speed < minSpeed) {
// Ensure backwards compatibility where stored speed was in range 5 - 25
speed = speed * 10;
// Store new playback speed in shared preferences
SharedPreferences.Editor editor = mSharedPreferences.edit();
editor.putInt(getString(R.string.preference_playback_speed_key), speed);
editor.apply();
}
float normalSpeed = Integer.parseInt(getString(R.string.preference_playback_speed_default));
setPlaybackSpeedIfInLegalRange((speed / normalSpeed));
}
Expand Down

0 comments on commit 4005007

Please sign in to comment.