diff options
author | daniel oeh <daniel.oeh@gmail.com> | 2013-05-03 18:31:39 +0200 |
---|---|---|
committer | daniel oeh <daniel.oeh@gmail.com> | 2013-05-03 18:31:39 +0200 |
commit | 62d7a927ad6a53b4ffa58bd8fef6368d698c3938 (patch) | |
tree | 47e3a2c79d2452d4c9ba3dbf46519b28c4b85b30 /src/de/danoeh/antennapod | |
parent | e65c1b7322327754d2f0cfc46138fe7fdab79693 (diff) | |
download | AntennaPod-62d7a927ad6a53b4ffa58bd8fef6368d698c3938.zip |
Added buttons to control playback speed
Diffstat (limited to 'src/de/danoeh/antennapod')
5 files changed, 78 insertions, 6 deletions
diff --git a/src/de/danoeh/antennapod/activity/AudioplayerActivity.java b/src/de/danoeh/antennapod/activity/AudioplayerActivity.java index b73a17125..f43f29db3 100644 --- a/src/de/danoeh/antennapod/activity/AudioplayerActivity.java +++ b/src/de/danoeh/antennapod/activity/AudioplayerActivity.java @@ -11,6 +11,7 @@ import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.ArrayAdapter; +import android.widget.Button; import android.widget.ImageButton; import android.widget.ImageView.ScaleType; import android.widget.ListView; @@ -57,6 +58,7 @@ public class AudioplayerActivity extends MediaplayerActivity { private TextView txtvTitle; private TextView txtvFeed; + private Button butPlaybackSpeed; private ImageButton butNavLeft; private ImageButton butNavRight; @@ -219,7 +221,7 @@ public class AudioplayerActivity extends MediaplayerActivity { if (savedPosition != -1) { switchToFragment(savedPosition); } - + } @Override @@ -365,6 +367,7 @@ public class AudioplayerActivity extends MediaplayerActivity { txtvFeed = (TextView) findViewById(R.id.txtvFeed); butNavLeft = (ImageButton) findViewById(R.id.butNavLeft); butNavRight = (ImageButton) findViewById(R.id.butNavRight); + butPlaybackSpeed = (Button) findViewById(R.id.butPlaybackSpeed); butNavLeft.setOnClickListener(new OnClickListener() { @@ -392,6 +395,50 @@ public class AudioplayerActivity extends MediaplayerActivity { } } }); + + butPlaybackSpeed.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + final double PLAYBACK_SPEED_STEP = 0.5; + final double PLAYBACK_SPEED_MAX = 2.0; + final double PLAYBACK_SPEED_DEFAULT = 1.0; + + if (controller != null && controller.canSetPlaybackSpeed()) { + double currentPlaybackSpeed = controller + .getCurrentPlaybackSpeedMultiplier(); + if (currentPlaybackSpeed != -1) { + if (currentPlaybackSpeed >= PLAYBACK_SPEED_MAX) { + controller.setPlaybackSpeed(PLAYBACK_SPEED_DEFAULT); + } else { + controller.setPlaybackSpeed(currentPlaybackSpeed + + PLAYBACK_SPEED_STEP); + } + } else { + controller.setPlaybackSpeed(PLAYBACK_SPEED_DEFAULT); + } + + } + } + }); + } + + @Override + protected void onPlaybackSpeedChange() { + super.onPlaybackSpeedChange(); + updateButPlaybackSpeed(); + } + + private void updateButPlaybackSpeed() { + double playbackSpeed; + if (controller == null + || (playbackSpeed = controller + .getCurrentPlaybackSpeedMultiplier()) == -1) { + butPlaybackSpeed.setVisibility(View.GONE); + } else { + butPlaybackSpeed.setVisibility(View.VISIBLE); + butPlaybackSpeed.setText(String.format("%.1fx", playbackSpeed)); + } } @Override @@ -423,7 +470,7 @@ public class AudioplayerActivity extends MediaplayerActivity { ((AudioplayerContentFragment) currentlyShownFragment) .onDataSetChanged(media); } - + updateButPlaybackSpeed(); } public void notifyMediaPositionChanged() { diff --git a/src/de/danoeh/antennapod/activity/MediaplayerActivity.java b/src/de/danoeh/antennapod/activity/MediaplayerActivity.java index 16b03809a..9fa9fbf52 100644 --- a/src/de/danoeh/antennapod/activity/MediaplayerActivity.java +++ b/src/de/danoeh/antennapod/activity/MediaplayerActivity.java @@ -132,10 +132,19 @@ public abstract class MediaplayerActivity extends SherlockFragmentActivity public void onPlaybackEnd() { finish(); } + + @Override + public void onPlaybackSpeedChange() { + MediaplayerActivity.this.onPlaybackSpeedChange(); + } }; } + protected void onPlaybackSpeedChange() { + + } + protected void onServiceQueried() { supportInvalidateOptionsMenu(); } diff --git a/src/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java b/src/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java index a50e820b6..e46017328 100644 --- a/src/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java +++ b/src/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java @@ -174,6 +174,12 @@ public class ExternalPlayerFragment extends SherlockFragment { .newOnPlayButtonClickListener()); } } + + @Override + public void onPlaybackSpeedChange() { + // TODO Auto-generated method stub + + } }; } diff --git a/src/de/danoeh/antennapod/service/PlaybackService.java b/src/de/danoeh/antennapod/service/PlaybackService.java index 421aae85e..bf90cf9c9 100644 --- a/src/de/danoeh/antennapod/service/PlaybackService.java +++ b/src/de/danoeh/antennapod/service/PlaybackService.java @@ -109,6 +109,7 @@ public class PlaybackService extends Service { public static final int NOTIFICATION_TYPE_BUFFER_END = 6; /** No more episodes are going to be played. */ public static final int NOTIFICATION_TYPE_PLAYBACK_END = 7; + public static final int NOTIFICATION_TYPE_PLAYBACK_SPEED_CHANGE = 8; /** * Returned by getPositionSafe() or getDurationSafe() if the playbackService @@ -1541,6 +1542,10 @@ public class PlaybackService extends Service { AudioPlayer audioPlayer = (AudioPlayer) player; if (audioPlayer.canSetSpeed()) { audioPlayer.setPlaybackSpeed((float) speed); + if (AppConfig.DEBUG) + Log.d(TAG, "Playback speed was set to " + speed); + sendNotificationBroadcast( + NOTIFICATION_TYPE_PLAYBACK_SPEED_CHANGE, 0); } } } @@ -1553,9 +1558,10 @@ public class PlaybackService extends Service { } } } - + public double getCurrentPlaybackSpeed() { - if (media.getMediaType() == MediaType.AUDIO && player instanceof AudioPlayer) { + if (media.getMediaType() == MediaType.AUDIO + && player instanceof AudioPlayer) { AudioPlayer audioPlayer = (AudioPlayer) player; if (audioPlayer.canSetSpeed()) { return audioPlayer.getCurrentSpeedMultiplier(); diff --git a/src/de/danoeh/antennapod/util/playback/PlaybackController.java b/src/de/danoeh/antennapod/util/playback/PlaybackController.java index b80cb54bc..0060c756f 100644 --- a/src/de/danoeh/antennapod/util/playback/PlaybackController.java +++ b/src/de/danoeh/antennapod/util/playback/PlaybackController.java @@ -327,6 +327,8 @@ public abstract class PlaybackController { break; case PlaybackService.NOTIFICATION_TYPE_PLAYBACK_END: onPlaybackEnd(); + case PlaybackService.NOTIFICATION_TYPE_PLAYBACK_SPEED_CHANGE: + onPlaybackSpeedChange(); break; } @@ -354,6 +356,8 @@ public abstract class PlaybackController { } } }; + + public abstract void onPlaybackSpeedChange(); public abstract void onShutdownNotification(); @@ -657,13 +661,13 @@ public abstract class PlaybackController { public boolean canSetPlaybackSpeed() { return playbackService != null && playbackService.canSetSpeed(); } - + public void setPlaybackSpeed(double speed) { if (playbackService != null) { playbackService.setSpeed(speed); } } - + public double getCurrentPlaybackSpeedMultiplier() { if (canSetPlaybackSpeed()) { return playbackService.getCurrentPlaybackSpeed(); |