Added buttons to control playback speed
This commit is contained in:
parent
e65c1b7322
commit
62d7a927ad
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
@ -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() {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -174,6 +174,12 @@ public class ExternalPlayerFragment extends SherlockFragment {
|
|||
.newOnPlayButtonClickListener());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlaybackSpeedChange() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1555,7 +1560,8 @@ 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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -355,6 +357,8 @@ public abstract class PlaybackController {
|
|||
}
|
||||
};
|
||||
|
||||
public abstract void onPlaybackSpeedChange();
|
||||
|
||||
public abstract void onShutdownNotification();
|
||||
|
||||
/** Called when the currently displayed information should be refreshed. */
|
||||
|
|
Loading…
Reference in New Issue