Implement stop after each track mode

This commit is contained in:
Mildred Ki'Lya 2011-11-01 12:19:42 +01:00
parent 81feb0f386
commit 56127d3393
8 changed files with 32 additions and 13 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 813 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 498 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

@ -34,6 +34,7 @@ THE SOFTWARE.
<string name="no_repeat">No repeat</string>
<string name="repeat">Repeat</string>
<string name="repeat_current_song">Repeat current song</string>
<string name="stop_current_song">Stop after current song</string>
<string name="random">Random</string>
<string name="random_enabling">Random enabled</string>
<string name="song_load_failed">Failed to load song %s. It may be corrupt or missing.</string>

View File

@ -263,6 +263,9 @@ public class PlaybackActivity extends Activity
case SongTimeline.FINISH_REPEAT_CURRENT:
mEndButton.setImageResource(R.drawable.repeat_current_active);
break;
case SongTimeline.FINISH_STOP_CURRENT:
mEndButton.setImageResource(R.drawable.stop_current_active);
break;
case SongTimeline.FINISH_RANDOM:
mEndButton.setImageResource(R.drawable.random_active);
break;
@ -499,6 +502,7 @@ public class PlaybackActivity extends Activity
menu.add(GROUP_FINISH, SongTimeline.FINISH_STOP, 0, R.string.no_repeat);
menu.add(GROUP_FINISH, SongTimeline.FINISH_REPEAT, 0, R.string.repeat);
menu.add(GROUP_FINISH, SongTimeline.FINISH_REPEAT_CURRENT, 0, R.string.repeat_current_song);
menu.add(GROUP_FINISH, SongTimeline.FINISH_STOP_CURRENT, 0, R.string.stop_current_song);
menu.add(GROUP_FINISH, SongTimeline.FINISH_RANDOM, 0, R.string.random);
}
}

View File

@ -158,8 +158,8 @@ public final class PlaybackService extends Service
/**
* These two bits will be one of SongTimeline.FINISH_*.
*/
public static final int MASK_FINISH = 0x3 << SHIFT_FINISH;
public static final int SHIFT_SHUFFLE = 6;
public static final int MASK_FINISH = 0x7 << SHIFT_FINISH;
public static final int SHIFT_SHUFFLE = 7;
/**
* These two bits will be one of SongTimeline.SHUFFLE_*.
*/
@ -169,14 +169,14 @@ public final class PlaybackService extends Service
* The PlaybackService state, indicating if the service is playing,
* repeating, etc.
*
* The format of this is 0b00000000_00000000_00000000_ffeedcba,
* The format of this is 0b00000000_00000000_00000000f_feeedcba,
* where each bit is:
* a: {@link PlaybackService#FLAG_PLAYING}
* b: {@link PlaybackService#FLAG_NO_MEDIA}
* c: {@link PlaybackService#FLAG_ERROR}
* d: {@link PlaybackService#FLAG_EMPTY_QUEUE}
* ee: {@link PlaybackService#MASK_FINISH}
* ff: {@link PlaybackService#MASK_SHUFFLE}
* a: {@link PlaybackService#FLAG_PLAYING}
* b: {@link PlaybackService#FLAG_NO_MEDIA}
* c: {@link PlaybackService#FLAG_ERROR}
* d: {@link PlaybackService#FLAG_EMPTY_QUEUE}
* eee: {@link PlaybackService#MASK_FINISH}
* ff: {@link PlaybackService#MASK_SHUFFLE}
*/
int mState;
private final Object mStateLock = new Object[0];
@ -808,12 +808,16 @@ public final class PlaybackService extends Service
@Override
public void onCompletion(MediaPlayer player)
{
if (finishAction(mState) == SongTimeline.FINISH_REPEAT_CURRENT)
if (finishAction(mState) == SongTimeline.FINISH_REPEAT_CURRENT) {
setCurrentSong(0);
else if (mTimeline.isEndOfQueue())
} else if (finishAction(mState) == SongTimeline.FINISH_STOP_CURRENT) {
unsetFlag(FLAG_PLAYING);
else
setCurrentSong(+1);
} else if (mTimeline.isEndOfQueue()) {
unsetFlag(FLAG_PLAYING);
} else {
setCurrentSong(+1);
}
}
@Override

View File

@ -64,12 +64,21 @@ public final class SongTimeline {
* @see SongTimeline#setFinishAction(int)
*/
public static final int FINISH_REPEAT_CURRENT = 2;
/**
* Stop playback after current song. This behavior is implemented entirely
* in {@link PlaybackService#onCompletion(android.media.MediaPlayer)};
* pressing the next or previous buttons will advance the song as normal;
* only allowing the song to play until the end.
*
* @see SongTimeline#setFinishAction(int)
*/
public static final int FINISH_STOP_CURRENT = 3;
/**
* Add random songs to the playlist.
*
* @see SongTimeline#setFinishAction(int)
*/
public static final int FINISH_RANDOM = 3;
public static final int FINISH_RANDOM = 4;
/**
* Clear the timeline and use only the provided songs.
@ -443,6 +452,7 @@ public final class SongTimeline {
case FINISH_STOP:
case FINISH_REPEAT:
case FINISH_REPEAT_CURRENT:
case FINISH_STOP_CURRENT:
if (size == 0)
// empty queue
return null;