[Android] New playback speed behaviour
Alexandre Perraud
git at videolan.org
Thu Jun 9 19:07:29 CEST 2016
vlc-android | branch: master | Alexandre Perraud <4leyx4ndre at gmail.com> | Thu Jun 9 18:57:00 2016 +0200| [e9102094d2965ad39aaa3dfae1199affa0510cf6] | committer: Alexandre Perraud
New playback speed behaviour
> https://code.videolan.org/videolan/vlc-android/commit/e9102094d2965ad39aaa3dfae1199affa0510cf6
---
vlc-android/res/layout/dialog_playback_speed.xml | 7 ++-
.../vlc/gui/dialogs/PlaybackSpeedDialog.java | 63 ++++++++++++++++++----
2 files changed, 58 insertions(+), 12 deletions(-)
diff --git a/vlc-android/res/layout/dialog_playback_speed.xml b/vlc-android/res/layout/dialog_playback_speed.xml
index f931f5f..aaf5f8d 100644
--- a/vlc-android/res/layout/dialog_playback_speed.xml
+++ b/vlc-android/res/layout/dialog_playback_speed.xml
@@ -83,7 +83,8 @@
android:max="200"
android:maxHeight="@dimen/seekbar_height"
android:minHeight="@dimen/seekbar_height"
- android:nextFocusUp="@+id/playback_speed_reset"
+ android:nextFocusUp="@+id/playback_speed_icon"
+ android:nextFocusDown="@+id/playback_speed_plus"
android:progress="100"
android:progressDrawable="@drawable/po_seekbar"
android:splitTrack="false"
@@ -104,6 +105,8 @@
android:layout_marginBottom="@dimen/half_default_margin"
android:clickable="true"
android:focusable="true"
+ android:nextFocusUp="@+id/playback_speed_seek"
+ android:nextFocusDown="@+id/playback_speed_minus"
android:src="@drawable/ic_plus_circle" />
<ImageView
@@ -112,6 +115,8 @@
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
+ android:nextFocusUp="@+id/playback_speed_plus"
+ android:nextFocusDown="@+id/playback_speed_icon"
android:src="@drawable/ic_minus_circle" />
</LinearLayout>
diff --git a/vlc-android/src/org/videolan/vlc/gui/dialogs/PlaybackSpeedDialog.java b/vlc-android/src/org/videolan/vlc/gui/dialogs/PlaybackSpeedDialog.java
index 3536faf..dea9979 100644
--- a/vlc-android/src/org/videolan/vlc/gui/dialogs/PlaybackSpeedDialog.java
+++ b/vlc-android/src/org/videolan/vlc/gui/dialogs/PlaybackSpeedDialog.java
@@ -45,7 +45,10 @@ public class PlaybackSpeedDialog extends DialogFragment implements PlaybackServi
private TextView mSpeedValue;
private SeekBar mSeekSpeed;
private ImageView mPlaybackSpeedIcon;
+ private ImageView mPlaybackSpeedPlus;
+ private ImageView mPlaybackSpeedMinus;
+ private boolean mSeekBarAction = false;
protected PlaybackService mService;
protected int mTextColor;
@@ -75,9 +78,13 @@ public class PlaybackSpeedDialog extends DialogFragment implements PlaybackServi
mSpeedValue = (TextView) view.findViewById(R.id.playback_speed_value);
mSeekSpeed = (SeekBar) view.findViewById(R.id.playback_speed_seek);
mPlaybackSpeedIcon = (ImageView) view.findViewById(R.id.playback_speed_icon);
+ mPlaybackSpeedPlus = (ImageView) view.findViewById(R.id.playback_speed_plus);
+ mPlaybackSpeedMinus = (ImageView) view.findViewById(R.id.playback_speed_minus);
mSeekSpeed.setOnSeekBarChangeListener(mSeekBarListener);
mPlaybackSpeedIcon.setOnClickListener(mResetListener);
+ mPlaybackSpeedPlus.setOnClickListener(mSpeedUpListener);
+ mPlaybackSpeedMinus.setOnClickListener(mSpeedDownListener);
mSpeedValue.setOnClickListener(mResetListener);
mTextColor = mSpeedValue.getCurrentTextColor();
@@ -94,10 +101,8 @@ public class PlaybackSpeedDialog extends DialogFragment implements PlaybackServi
private void setRateProgress() {
double speed = mService.getRate();
- if (speed != 1.0d) {
- speed = 100 * (1 + Math.log(speed) / Math.log(4));
- mSeekSpeed.setProgress((int) speed);
- }
+ speed = 100 * (1 + Math.log(speed) / Math.log(4));
+ mSeekSpeed.setProgress((int) speed);
updateInterface();
}
@@ -106,17 +111,19 @@ public class PlaybackSpeedDialog extends DialogFragment implements PlaybackServi
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (mService == null)
return;
-
- float rate = (float) Math.pow(4, ((double) progress / (double) 100) - 1);
- mSpeedValue.setText(Strings.formatRateString(rate));
- mService.setRate(rate);
- updateInterface();
+ if (mSeekBarAction == true) {
+ float rate = (float) Math.pow(4, ((double) progress / (double) 100) - 1);
+ mService.setRate(rate);
+ updateInterface();
+ }
}
public void onStartTrackingTouch(SeekBar seekBar) {
+ mSeekBarAction = true;
}
public void onStopTrackingTouch(SeekBar seekBar) {
+ mSeekBarAction = false;
}
};
@@ -129,13 +136,47 @@ public class PlaybackSpeedDialog extends DialogFragment implements PlaybackServi
if (mService.getRate() == 1.0d)
return;
- mSeekSpeed.setProgress(100);
mService.setRate(1);
+ setRateProgress();
+ }
+ };
+
+ private View.OnClickListener mSpeedUpListener = new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if (mService == null)
+ return;
+ changeSpeed(0.05f);
+ setRateProgress();
}
};
+ private View.OnClickListener mSpeedDownListener = new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if (mService == null)
+ return;
+ changeSpeed(-0.05f);
+ setRateProgress();
+ }
+ };
+
+ public void changeSpeed(float delta){
+ double initialRate = Math.round(mService.getRate() * 100d) / 100d;
+ if (delta>0)
+ initialRate = Math.floor((initialRate + 0.005d) / 0.05d) * 0.05d;
+ else
+ initialRate = Math.ceil((initialRate - 0.005d) / 0.05d) * 0.05d;
+ float rate = Math.round((initialRate + delta) * 100f) / 100f;
+ if (rate < 0.25f || rate > 4f)
+ return;
+ mService.setRate(rate);
+ }
+
private void updateInterface() {
- if (mService.getRate() != 1.0d) {
+ float rate = mService.getRate();
+ mSpeedValue.setText(Strings.formatRateString(rate));
+ if (rate != 1.0f) {
mPlaybackSpeedIcon.setImageResource(R.drawable.ic_speed_reset);
mSpeedValue.setTextColor(getResources().getColor(R.color.orange500));
} else {
More information about the Android
mailing list