diff --git a/res/values/arrays.xml b/res/values/arrays.xml index 9757b60e..09307ca9 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -53,6 +53,7 @@ THE SOFTWARE. Enqueue Current Album Enqueue Current Artist Enqueue Current Genre + Clear Queue Starting up... diff --git a/src/org/kreed/vanilla/PlaybackActivity.java b/src/org/kreed/vanilla/PlaybackActivity.java index 3e183631..62a5477c 100644 --- a/src/org/kreed/vanilla/PlaybackActivity.java +++ b/src/org/kreed/vanilla/PlaybackActivity.java @@ -49,6 +49,7 @@ public class PlaybackActivity extends Activity implements Handler.Callback, View public static final int ACTION_ENQUEUE_ALBUM = 7; public static final int ACTION_ENQUEUE_ARTIST = 8; public static final int ACTION_ENQUEUE_GENRE = 9; + public static final int ACTION_CLEAR_QUEUE = 10; public static int mUpAction; public static int mDownAction; @@ -402,6 +403,10 @@ public class PlaybackActivity extends Activity implements Handler.Callback, View case ACTION_ENQUEUE_GENRE: enqueue(MediaUtils.TYPE_GENRE); break; + case ACTION_CLEAR_QUEUE: + ContextApplication.getService().clearQueue(); + Toast.makeText(this, R.string.queue_cleared, Toast.LENGTH_SHORT).show(); + break; default: throw new IllegalArgumentException("Invalid action: " + action); } diff --git a/src/org/kreed/vanilla/PlaybackService.java b/src/org/kreed/vanilla/PlaybackService.java index 9bd63d38..a8b0a287 100644 --- a/src/org/kreed/vanilla/PlaybackService.java +++ b/src/org/kreed/vanilla/PlaybackService.java @@ -1041,6 +1041,14 @@ public final class PlaybackService extends Service implements Handler.Callback, return count; } + /** + * Clear the song queue. + */ + public void clearQueue() + { + mTimeline.clearQueue(); + } + /** * Reset the position at which songs are enqueued. That is, the next song * enqueued will be placed directly after the playing song. diff --git a/src/org/kreed/vanilla/SongTimeline.java b/src/org/kreed/vanilla/SongTimeline.java index d25bc708..8b3c422b 100644 --- a/src/org/kreed/vanilla/SongTimeline.java +++ b/src/org/kreed/vanilla/SongTimeline.java @@ -439,6 +439,19 @@ public final class SongTimeline { } } + /** + * Clear the song queue. + */ + public void clearQueue() + { + synchronized (this) { + mSongs.subList(mCurrentPos + 1, mSongs.size()).clear(); + mQueueOffset = 0; + } + + mCallback.songReplaced(+1, getSong(+1)); + } + /** * Remove the song with the given id from the timeline. *