开发者

Android: Browse audio playlist and open a M3U file from an app

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.


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


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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜