Music Intent - Jump to Artist/Album

All your problems with Audio, Video and Images.

Music Intent - Jump to Artist/Album

Postby timhoeck » Fri Feb 20, 2009 2:15 am

I am trying to find a way to start an intent that will send you directly to a specific Artist or Album in the default Music player.

I've attempted something like the following:

Code: Select all
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(ContentUris.withAppendedId(MediaStore.Audio.Artists.EXTERNAL_CONTENT_URI, ArtistId));
startActivity(intent);


This results in logcat reporting that there is no activity found to handle for: ACTION_VIEW with a URI of content://media/external/audio/artist/1

This will open the music player, but it is using the id as media id (i.e. a specific track):

Code: Select all
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(ContentUris.withAppendedId(Media.EXTERNAL_CONTENT_URI, ArtistId));
startActivity(intent);


Is there a complete list of available URI's with supported Actions that are implemented in default Android apps? I know OpenIntents has a list, but is there anything official from Google?
timhoeck
Junior Developer
Junior Developer
 
Posts: 22
Joined: Fri Jan 16, 2009 4:41 pm

Top

Postby timhoeck » Sat Feb 21, 2009 9:33 pm

So I guess there is no URI to jump to Artist/Album for the Music player, so I went for playlists.

Instead, I searched all songs by the artists or albums, and generated a playlist for them, but now I can't automatically start playing that playlist, the best I can do is send the user to the playlist browser. The problem is it looks like there is no URI to pick a playlist either (http://code.google.com/p/android/issues/detail?id=958).
timhoeck
Junior Developer
Junior Developer
 
Posts: 22
Joined: Fri Jan 16, 2009 4:41 pm

Postby timhoeck » Wed Feb 25, 2009 3:40 am

I ended up finding:

For Artist (to go to albums by the artist):
Code: Select all
String artist = "Artist Name";
Cursor artists = mContext.getContentResolver().query(MediaStore.Audio.Artists.EXTERNAL_CONTENT_URI, new String[] {MediaStore.Audio.Artists._ID, MediaStore.Audio.Artists.ARTIST}, MediaStore.Audio.Artists.ARTIST + "=?", artist, null);
int artistID = artists.getInt(artists.getColumnIndex(MediaStore.Audio.Artists._ID));
if (artists.moveToFirst()) {
  Intent intent = new Intent(Intent.ACTION_PICK);
  intent.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/album");
  intent.putExtra("artist", id);
  startActivity(intent);
}


For Album (to go to tracks on an album):
Code: Select all
String album = "Album Name";
Cursor albums = mContext.getContentResolver().query(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, new String[] {MediaStore.Audio.Albums._ID, MediaStore.Audio.Albums.ALBUM}, MediaStore.Audio.Albums.ALBUM + "=?", album, null);
if (albums.moveToFirst()) {
  Intent intent = new Intent(Intent.ACTION_PICK);
  intent.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track");
  intent.putExtra("album", id);
  startActivity(intent);
}
timhoeck
Junior Developer
Junior Developer
 
Posts: 22
Joined: Fri Jan 16, 2009 4:41 pm

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 15 guests