import android.os.Message;
import android.os.SystemClock;
import android.provider.MediaStore.Audio.Playlists;
+import android.provider.MediaStore.Audio.Albums;
+import android.provider.MediaStore.Audio.Artists;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.view.Menu;
}
+ private long parseIdFromIntent(Intent intent, String longKey,
+ String stringKey, long defaultId) {
+ long id = intent.getLongExtra(longKey, -1);
+ if (id < 0) {
+ String idString = intent.getStringExtra(stringKey);
+ if (idString != null) {
+ try {
+ id = Long.parseLong(idString);
+ } catch (NumberFormatException e) {
+ // ignore
+ }
+ }
+ }
+ return id;
+ }
+
/**
* Checks whether the passed intent contains a playback request,
* and starts playback if that's the case
MusicUtils.playFile(this, uri);
handled = true;
} else if (Playlists.CONTENT_TYPE.equals(mimeType)) {
- long id = intent.getLongExtra("playlistId", -1);
- if (id < 0) {
- String idString = intent.getStringExtra("playlist");
- if (idString != null) {
- try {
- id = Long.parseLong(idString);
- } catch (NumberFormatException e) {
- // ignore
- }
- }
- }
+ long id = parseIdFromIntent(intent, "playlistId", "playlist", -1);
if (id >= 0) {
MusicUtils.playPlaylist(this, id);
handled = true;
}
+ } else if (Albums.CONTENT_TYPE.equals(mimeType)) {
+ long id = parseIdFromIntent(intent, "albumId", "album", -1);
+ if (id >= 0) {
+ int position = intent.getIntExtra("position", 0);
+ MusicUtils.playAlbum(this, id, position);
+ handled = true;
+ }
+ } else if (Artists.CONTENT_TYPE.equals(mimeType)) {
+ long id = parseIdFromIntent(intent, "artistId", "artist", -1);
+ if (id >= 0) {
+ int position = intent.getIntExtra("position", 0);
+ MusicUtils.playArtist(this, id, position);
+ handled = true;
+ }
}
if (handled) {
}
/**
+ * Plays songs by an artist.
+ *
+ * @param context The {@link Context} to use.
+ * @param artistId The artist Id.
+ * @param position Specify where to start.
+ */
+ public static void playArtist(final Context context, final long artistId, int position) {
+ final long[] artistList = getSongListForArtist(context, artistId);
+ if (artistList != null) {
+ playAll(context, artistList, position, false);
+ }
+ }
+
+ /**
* @param context The {@link Context} to use.
* @param id The ID of the genre.
* @return The song list for an genre.
return id;
}
+ /**
+ * Plays songs from an album.
+ *
+ * @param context The {@link Context} to use.
+ * @param albumId The album Id.
+ * @param position Specify where to start.
+ */
+ public static void playAlbum(final Context context, final long albumId, int position) {
+ final long[] albumList = getSongListForAlbum(context, albumId);
+ if (albumList != null) {
+ playAll(context, albumList, position, false);
+ }
+ }
+
/* */
public static void makeInsertItems(final long[] ids, final int offset, int len, final int base) {
if (offset + len > ids.length) {