summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--res/layout-land/audioplayer_activity.xml17
-rw-r--r--res/layout/audioplayer_activity.xml13
-rw-r--r--src/de/danoeh/antennapod/activity/AudioplayerActivity.java51
-rw-r--r--src/de/danoeh/antennapod/activity/MediaplayerActivity.java9
-rw-r--r--src/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java6
-rw-r--r--src/de/danoeh/antennapod/service/PlaybackService.java10
-rw-r--r--src/de/danoeh/antennapod/util/playback/PlaybackController.java8
7 files changed, 102 insertions, 12 deletions
diff --git a/res/layout-land/audioplayer_activity.xml b/res/layout-land/audioplayer_activity.xml
index 521dbc68a..1e671c745 100644
--- a/res/layout-land/audioplayer_activity.xml
+++ b/res/layout-land/audioplayer_activity.xml
@@ -92,14 +92,12 @@
android:layout_width="80dp"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
- android:layout_marginLeft="8dp"
- android:layout_marginRight="8dp"
android:background="?attr/borderless_button"
android:src="?attr/av_pause" />
<ImageButton
android:id="@+id/butRev"
- android:layout_width="80dp"
+ android:layout_width="60dp"
android:layout_height="match_parent"
android:layout_toLeftOf="@id/butPlay"
android:background="?attr/borderless_button"
@@ -107,11 +105,22 @@
<ImageButton
android:id="@+id/butFF"
- android:layout_width="80dp"
+ android:layout_width="60dp"
android:layout_height="match_parent"
android:layout_toRightOf="@id/butPlay"
android:background="?attr/borderless_button"
android:src="?attr/av_fast_forward" />
+
+ <Button
+ android:id="@+id/butPlaybackSpeed"
+ android:layout_width="60dp"
+ android:layout_height="match_parent"
+ android:layout_toRightOf="@id/butFF"
+ android:background="?attr/borderless_button"
+ android:src="?attr/av_fast_forward"
+ android:textColor="@color/gray"
+ android:textSize="@dimen/text_size_medium"
+ android:visibility="gone" />
</RelativeLayout>
<RelativeLayout
diff --git a/res/layout/audioplayer_activity.xml b/res/layout/audioplayer_activity.xml
index bf7540ed1..857d7140f 100644
--- a/res/layout/audioplayer_activity.xml
+++ b/res/layout/audioplayer_activity.xml
@@ -79,8 +79,6 @@
android:layout_width="80dp"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
- android:layout_marginLeft="12dp"
- android:layout_marginRight="12dp"
android:background="?attr/borderless_button"
android:src="?attr/av_pause" />
@@ -99,6 +97,17 @@
android:layout_toRightOf="@id/butPlay"
android:background="?attr/borderless_button"
android:src="?attr/av_fast_forward" />
+
+ <Button
+ android:id="@+id/butPlaybackSpeed"
+ android:layout_width="80dp"
+ android:layout_height="match_parent"
+ android:layout_toRightOf="@id/butFF"
+ android:background="?attr/borderless_button"
+ android:src="?attr/av_fast_forward"
+ android:textColor="@color/gray"
+ android:textSize="@dimen/text_size_medium"
+ android:visibility="gone" />
</RelativeLayout>
<RelativeLayout
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();