Refactor PlaybackService start intents
It's a bit confusing as it is and was not properly playing for the autoplay intents
This commit is contained in:
parent
fb53c329bb
commit
2ad4e90cda
@ -284,7 +284,7 @@ public final class PlaybackService extends Service implements Handler.Callback,
|
|||||||
String action = intent.getAction();
|
String action = intent.getAction();
|
||||||
|
|
||||||
if (ACTION_TOGGLE_PLAYBACK.equals(action)) {
|
if (ACTION_TOGGLE_PLAYBACK.equals(action)) {
|
||||||
go(0, false);
|
playPause();
|
||||||
} else if (ACTION_TOGGLE_PLAYBACK_DELAYED.equals(action)) {
|
} else if (ACTION_TOGGLE_PLAYBACK_DELAYED.equals(action)) {
|
||||||
if (mHandler.hasMessages(CALL_GO, Integer.valueOf(0))) {
|
if (mHandler.hasMessages(CALL_GO, Integer.valueOf(0))) {
|
||||||
mHandler.removeMessages(CALL_GO, Integer.valueOf(0));
|
mHandler.removeMessages(CALL_GO, Integer.valueOf(0));
|
||||||
@ -293,9 +293,11 @@ public final class PlaybackService extends Service implements Handler.Callback,
|
|||||||
mHandler.sendMessageDelayed(mHandler.obtainMessage(CALL_GO, Integer.valueOf(0)), 400);
|
mHandler.sendMessageDelayed(mHandler.obtainMessage(CALL_GO, Integer.valueOf(0)), 400);
|
||||||
}
|
}
|
||||||
} else if (ACTION_NEXT_SONG.equals(action)) {
|
} else if (ACTION_NEXT_SONG.equals(action)) {
|
||||||
go(1, false);
|
setCurrentSong(1);
|
||||||
|
userActionTriggered();
|
||||||
} else if (ACTION_NEXT_SONG_AUTOPLAY.equals(action)) {
|
} else if (ACTION_NEXT_SONG_AUTOPLAY.equals(action)) {
|
||||||
go(1, true);
|
setCurrentSong(1);
|
||||||
|
play();
|
||||||
} else if (ACTION_NEXT_SONG_DELAYED.equals(action)) {
|
} else if (ACTION_NEXT_SONG_DELAYED.equals(action)) {
|
||||||
if (mHandler.hasMessages(CALL_GO, Integer.valueOf(1))) {
|
if (mHandler.hasMessages(CALL_GO, Integer.valueOf(1))) {
|
||||||
mHandler.removeMessages(CALL_GO, Integer.valueOf(1));
|
mHandler.removeMessages(CALL_GO, Integer.valueOf(1));
|
||||||
@ -304,9 +306,11 @@ public final class PlaybackService extends Service implements Handler.Callback,
|
|||||||
mHandler.sendMessageDelayed(mHandler.obtainMessage(CALL_GO, Integer.valueOf(1)), 400);
|
mHandler.sendMessageDelayed(mHandler.obtainMessage(CALL_GO, Integer.valueOf(1)), 400);
|
||||||
}
|
}
|
||||||
} else if (ACTION_PREVIOUS_SONG.equals(action)) {
|
} else if (ACTION_PREVIOUS_SONG.equals(action)) {
|
||||||
go(-1, false);
|
setCurrentSong(-1);
|
||||||
|
userActionTriggered();
|
||||||
} else if (ACTION_PREVIOUS_SONG_AUTOPLAY.equals(action)) {
|
} else if (ACTION_PREVIOUS_SONG_AUTOPLAY.equals(action)) {
|
||||||
go(-1, true);
|
setCurrentSong(-1);
|
||||||
|
play();
|
||||||
} else if (ACTION_PLAY.equals(action)) {
|
} else if (ACTION_PLAY.equals(action)) {
|
||||||
play();
|
play();
|
||||||
} else if (ACTION_PAUSE.equals(action)) {
|
} else if (ACTION_PAUSE.equals(action)) {
|
||||||
@ -790,22 +794,6 @@ public final class PlaybackService extends Service implements Handler.Callback,
|
|||||||
return mTimeline.getSong(delta);
|
return mTimeline.getSong(delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void go(int delta, boolean autoPlay)
|
|
||||||
{
|
|
||||||
if (autoPlay) {
|
|
||||||
synchronized (mStateLock) {
|
|
||||||
mState |= FLAG_PLAYING;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (delta == 0)
|
|
||||||
playPause();
|
|
||||||
else
|
|
||||||
setCurrentSong(delta);
|
|
||||||
|
|
||||||
userActionTriggered();
|
|
||||||
}
|
|
||||||
|
|
||||||
private class Receiver extends BroadcastReceiver {
|
private class Receiver extends BroadcastReceiver {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context content, Intent intent)
|
public void onReceive(Context content, Intent intent)
|
||||||
@ -905,9 +893,8 @@ public final class PlaybackService extends Service implements Handler.Callback,
|
|||||||
*/
|
*/
|
||||||
private static final int FADE_OUT = 7;
|
private static final int FADE_OUT = 7;
|
||||||
/**
|
/**
|
||||||
* Calls {@link PlaybackService#go(int, boolean)} with the given delta.
|
* If arg1 is 0, calls {@link PlaybackService#playPause()}.
|
||||||
*
|
* Otherwise, calls {@link PlaybackService#setCurrentSong(int)} with arg1.
|
||||||
* obj should an Integer representing the delta to pass to go.
|
|
||||||
*/
|
*/
|
||||||
private static final int CALL_GO = 8;
|
private static final int CALL_GO = 8;
|
||||||
private static final int BROADCAST_CHANGE = 10;
|
private static final int BROADCAST_CHANGE = 10;
|
||||||
@ -919,8 +906,10 @@ public final class PlaybackService extends Service implements Handler.Callback,
|
|||||||
{
|
{
|
||||||
switch (message.what) {
|
switch (message.what) {
|
||||||
case CALL_GO:
|
case CALL_GO:
|
||||||
int delta = (Integer)message.obj;
|
if (message.arg1 == 0)
|
||||||
go(delta, false);
|
playPause();
|
||||||
|
else
|
||||||
|
setCurrentSong(message.arg1);
|
||||||
break;
|
break;
|
||||||
case SAVE_STATE:
|
case SAVE_STATE:
|
||||||
// For unexpected terminations: crashes, task killers, etc.
|
// For unexpected terminations: crashes, task killers, etc.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user