diff --git a/res/drawable-hdpi/stop_active.png b/res/drawable-hdpi/stop_active.png new file mode 100644 index 00000000..44732308 Binary files /dev/null and b/res/drawable-hdpi/stop_active.png differ diff --git a/res/drawable-hdpi/stop_current_active.png b/res/drawable-hdpi/stop_current_active.png new file mode 100644 index 00000000..59cce0ed Binary files /dev/null and b/res/drawable-hdpi/stop_current_active.png differ diff --git a/res/drawable-mdpi/stop_active.png b/res/drawable-mdpi/stop_active.png new file mode 100644 index 00000000..3cdb9f5d Binary files /dev/null and b/res/drawable-mdpi/stop_active.png differ diff --git a/res/drawable-mdpi/stop_current_active.png b/res/drawable-mdpi/stop_current_active.png new file mode 100644 index 00000000..a9e0e6f7 Binary files /dev/null and b/res/drawable-mdpi/stop_current_active.png differ diff --git a/res/values/translatable.xml b/res/values/translatable.xml index b00e586a..4cd674a2 100644 --- a/res/values/translatable.xml +++ b/res/values/translatable.xml @@ -34,6 +34,7 @@ THE SOFTWARE. No repeat Repeat Repeat current song + Stop after current song Random Random enabled Failed to load song %s. It may be corrupt or missing. diff --git a/src/org/kreed/vanilla/PlaybackActivity.java b/src/org/kreed/vanilla/PlaybackActivity.java index f0e4b4a9..a6183748 100644 --- a/src/org/kreed/vanilla/PlaybackActivity.java +++ b/src/org/kreed/vanilla/PlaybackActivity.java @@ -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); } } diff --git a/src/org/kreed/vanilla/PlaybackService.java b/src/org/kreed/vanilla/PlaybackService.java index 9f8f1cff..aa77adb7 100644 --- a/src/org/kreed/vanilla/PlaybackService.java +++ b/src/org/kreed/vanilla/PlaybackService.java @@ -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 diff --git a/src/org/kreed/vanilla/SongTimeline.java b/src/org/kreed/vanilla/SongTimeline.java index 9c5e0f18..b9fb57bb 100644 --- a/src/org/kreed/vanilla/SongTimeline.java +++ b/src/org/kreed/vanilla/SongTimeline.java @@ -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;