Play/Pause button now toggles startWhenPrepared when PlaybackService is
in PREPARING state
This commit is contained in:
parent
af2595f2d0
commit
8a76daeeaf
|
@ -90,13 +90,25 @@ public abstract class MediaplayerActivity extends SherlockFragmentActivity
|
||||||
protected OnClickListener playbuttonListener = new OnClickListener() {
|
protected OnClickListener playbuttonListener = new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if (status == PlayerStatus.PLAYING) {
|
if (playbackService != null) {
|
||||||
playbackService.pause(true);
|
switch (status) {
|
||||||
} else if (status == PlayerStatus.PAUSED
|
case PLAYING:
|
||||||
|| status == PlayerStatus.PREPARED) {
|
playbackService.pause(true);
|
||||||
playbackService.play();
|
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() {
|
protected ServiceConnection mConnection = new ServiceConnection() {
|
||||||
public void onServiceConnected(ComponentName className, IBinder service) {
|
public void onServiceConnected(ComponentName className, IBinder service) {
|
||||||
|
@ -410,6 +422,13 @@ public abstract class MediaplayerActivity extends SherlockFragmentActivity
|
||||||
case PREPARING:
|
case PREPARING:
|
||||||
postStatusMsg(R.string.player_preparing_msg);
|
postStatusMsg(R.string.player_preparing_msg);
|
||||||
loadMediaInfo();
|
loadMediaInfo();
|
||||||
|
if (playbackService != null) {
|
||||||
|
if (playbackService.isStartWhenPrepared()) {
|
||||||
|
butPlay.setImageResource(R.drawable.av_pause);
|
||||||
|
} else {
|
||||||
|
butPlay.setImageResource(R.drawable.av_play);
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case STOPPED:
|
case STOPPED:
|
||||||
postStatusMsg(R.string.player_stopped_msg);
|
postStatusMsg(R.string.player_stopped_msg);
|
||||||
|
|
|
@ -658,6 +658,11 @@ public class PlaybackService extends Service {
|
||||||
updateWidget();
|
updateWidget();
|
||||||
refreshRemoteControlClientState();
|
refreshRemoteControlClientState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Send ACTION_PLAYER_STATUS_CHANGED without changing the status attribute. */
|
||||||
|
private void postStatusUpdateIntent() {
|
||||||
|
setStatus(status);
|
||||||
|
}
|
||||||
|
|
||||||
private void sendNotificationBroadcast(int type, int code) {
|
private void sendNotificationBroadcast(int type, int code) {
|
||||||
Intent intent = new Intent(ACTION_PLAYER_NOTIFICATION);
|
Intent intent = new Intent(ACTION_PLAYER_NOTIFICATION);
|
||||||
|
@ -992,4 +997,15 @@ public class PlaybackService extends Service {
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isStartWhenPrepared() {
|
||||||
|
return startWhenPrepared;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStartWhenPrepared(boolean startWhenPrepared) {
|
||||||
|
this.startWhenPrepared = startWhenPrepared;
|
||||||
|
postStatusUpdateIntent();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue