1

I am trying to find a way to browse audio playlist and return and save the Uri of the playlist to play it later.

Like an alarm clock which you can select the playlist to paly it later when alarm starts.

It is possible to get one song's URI, with intent but it doesn't work on playlist.

I have tried the intent,

Intent i = new Intent(Intent.ACTION_PICK);
i.setType(MediaStore.Audio.Playlists.CONTENT_TYPE);
startActivity(i);

but it doesn't return URI, it runs MediaPlayback activity directly.

Any idea on this?

Thanks in advance.

Mike
  • 2,132
  • 3
  • 20
  • 33
Shabnam
  • 21
  • 1
  • 5

2 Answers2

0

This is the code that should work for playlists:

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setComponent(new ComponentName
("com.android.music","com.android.music.PlaylistBrowserActivity"));
intent.setType(MediaStore.Audio.Playlists.CONTENT_TYPE);
intent.setFlags(0x10000000);
intent.putExtra("oneshot", false);
intent.putExtra("playlist", playlistid);
startActivity(intent);

and to retrieve the playlistid:

Cursor cursor = getContentResolver().query
(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, null, null, null,
null);
if (cursor != null) {
 if (cursor.moveToFirst()) {
  do {
     playlistid = cursor.getString(cursor.getColumnIndex
(MediaStore.Audio.Playlists._ID));
     playList.add(playlist);
     } while (cursor.moveToNext());
     cursor.close();
 }
}

(copied from http://www.androiddiscuss.com/1-android-discuss/29092.html)

Ranbir
  • 81
  • 1
  • 2
0

Try using Intent.ACTION_GET_CONTENT instead of Intent.ACTION_PICK, and using startActivityForResult() instead of startActivity()

Geobits
  • 22,218
  • 6
  • 59
  • 103
  • Thanks for the answer! I have tried it but I get "no application can perform this action" error. Do you think that is it becasue I am running it on emulator? have you tried it on emulator? – Shabnam May 31 '11 at 05:24
  • I haven't personally used a playlist intent, just individual mp3's. However, take a look at this [forum topic](http://www.androiddiscuss.com/1-android-discuss/29092.html). It has some code that supposedly works for this. – Geobits May 31 '11 at 06:37