Play/Pause button now toggles startWhenPrepared when PlaybackService is

in PREPARING state
This commit is contained in:
daniel oeh 2012-09-04 13:32:48 +02:00
parent af2595f2d0
commit 8a76daeeaf
2 changed files with 40 additions and 5 deletions

View File

@ -90,13 +90,25 @@ public abstract class MediaplayerActivity extends SherlockFragmentActivity
protected OnClickListener playbuttonListener = new OnClickListener() {
@Override
public void onClick(View v) {
if (status == PlayerStatus.PLAYING) {
if (playbackService != null) {
switch (status) {
case PLAYING:
playbackService.pause(true);
} else if (status == PlayerStatus.PAUSED
|| status == PlayerStatus.PREPARED) {
break;
case PAUSED:
case PREPARED:
playbackService.play();
break;
case PREPARING:
playbackService.setStartWhenPrepared(!playbackService
.isStartWhenPrepared());
}
} else {
Log.w(TAG,
"Play/Pause button was pressed, but playbackservice was null!");
}
}
};
protected ServiceConnection mConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder service) {
@ -410,6 +422,13 @@ public abstract class MediaplayerActivity extends SherlockFragmentActivity
case PREPARING:
postStatusMsg(R.string.player_preparing_msg);
loadMediaInfo();
if (playbackService != null) {
if (playbackService.isStartWhenPrepared()) {
butPlay.setImageResource(R.drawable.av_pause);
} else {
butPlay.setImageResource(R.drawable.av_play);
}
}
break;
case STOPPED:
postStatusMsg(R.string.player_stopped_msg);

View File

@ -659,6 +659,11 @@ public class PlaybackService extends Service {
refreshRemoteControlClientState();
}
/** Send ACTION_PLAYER_STATUS_CHANGED without changing the status attribute. */
private void postStatusUpdateIntent() {
setStatus(status);
}
private void sendNotificationBroadcast(int type, int code) {
Intent intent = new Intent(ACTION_PLAYER_NOTIFICATION);
intent.putExtra(EXTRA_NOTIFICATION_TYPE, type);
@ -992,4 +997,15 @@ public class PlaybackService extends Service {
return player;
}
public boolean isStartWhenPrepared() {
return startWhenPrepared;
}
public void setStartWhenPrepared(boolean startWhenPrepared) {
this.startWhenPrepared = startWhenPrepared;
postStatusUpdateIntent();
}
}