In my Android application, I want the user to be able to select Albums, Artists and Playlists and then send an intent for their default media player to play them.
I fetch the ID in the standard way:
final Uri exAudioUri = Uri.parse("content://com.google.android.music.MusicContent/playlists");
final String[] proj = { MediaStore.Audio.Playlists._ID, MediaStore.Audio.Playlists.NAME };
final Cursor musiccursor = ctx.getContentResolver().query(exAudioUri, proj, null, null, null);
String name = null;
String id = null;
if (musiccursor != null && musiccursor.getCount() > 0) {
while (musiccursor.moveToNext()) {
name = musiccursor.getString(musiccursor.getColumnIndexOrThrow(MediaStore.Audio.Playlists.NAME));
id = musiccursor.getString(musiccursor.getColumnIndexOrThrow(MediaStore.Audio.Playlists._ID));
For Playlists I'm using the following intent:
Intent playMediaIntent = new Intent(Intent.ACTION_VIEW);
playMediaIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
playMediaIntent.setType(MediaStore.Audio.Playlists.CONTENT_TYPE);
playMediaIntent.putExtra("playlist", playlistID);
The Google Play Music app intercepts this and plays the playlist successfully.
Trying to do the same for albums gives me an activity not found exception:
Intent playMediaIntent = new Intent(Intent.ACTION_VIEW);
playMediaIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//playMediaIntent.setType("vnd.android.cursor.dir/track");
playMediaIntent.setType(MediaStore.Audio.Albums.CONTENT_TYPE);
//playMediaIntent.setData(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI);
playMediaIntent.putExtra("album", albumID);
I know these are undocumented methods and subject to change, but I don't want to have to implement an entire media player of my own, when a user will already have chosen their favourite....
Can anyone suggest any 'standard' code that media players will intercept?
Alternatively, is there a way to get all of the songs from the album (or artist) and send an intent with data containing an array of track URIs to play or queue up??
Been to the depths of Google/Stackoverflow on this one and drawn a blank...
Please help! I thank you in advance.