[Android] Fix getExistingInstance usage in SpeedSelector
Jean-Baptiste Kempf
git at videolan.org
Mon Oct 15 14:35:14 CEST 2012
vlc-ports/android | branch: master | Jean-Baptiste Kempf <jb at videolan.org> | Mon Oct 15 14:22:07 2012 +0200| [8662c2f34c23e8a9f955ae286459725dd11b18bd] | committer: Jean-Baptiste Kempf
Fix getExistingInstance usage in SpeedSelector
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=8662c2f34c23e8a9f955ae286459725dd11b18bd
---
.../org/videolan/vlc/gui/SpeedSelectorDialog.java | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/SpeedSelectorDialog.java b/vlc-android/src/org/videolan/vlc/gui/SpeedSelectorDialog.java
index 2e664ec..fc125a4 100644
--- a/vlc-android/src/org/videolan/vlc/gui/SpeedSelectorDialog.java
+++ b/vlc-android/src/org/videolan/vlc/gui/SpeedSelectorDialog.java
@@ -46,14 +46,21 @@ public class SpeedSelectorDialog extends Dialog {
final TextView speedLabel = (TextView)findViewById(R.id.current_speed);
Button resetButton = (Button)findViewById(R.id.reset);
- speedLabel.setText(String.format(java.util.Locale.US, "%.2fx", LibVLC.getExistingInstance().getRate()));
- seekbar.setProgress( (int)( ((Math.log(LibVLC.getExistingInstance().getRate()) / Math.log(4)) + 1) * 100) );
- seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
+ float rate;
+ LibVLC libVLC = LibVLC.getExistingInstance();
+ if (libVLC != null)
+ rate = libVLC.getRate();
+ else
+ rate = (float) 1.0;
+
+ speedLabel.setText(String.format(java.util.Locale.US, "%.2fx", rate));
+ seekbar.setProgress((int) (((Math.log(rate) / Math.log(4)) + 1) * 100));
+ seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
- float rate = (float) Math.pow((double)4, ((double)progress/(double)100) - (double)1);
+ float rate = (float) Math.pow(4, ((double)progress/(double)100) - 1);
speedLabel.setText(String.format(java.util.Locale.US, "%.2fx", rate));
LibVLC.getExistingInstance().setRate(rate);
}
@@ -63,12 +70,12 @@ public class SpeedSelectorDialog extends Dialog {
@Override
public void onStopTrackingTouch(SeekBar seekBar) { }
});
- resetButton.setOnClickListener(new View.OnClickListener() {
+ resetButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
seekbar.setProgress(100);
- LibVLC.getExistingInstance().setRate((float)1);
+ LibVLC.getExistingInstance().setRate(1);
}
});
}
More information about the Android
mailing list