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

╄→尐↘猪︶ㄣ 提交于 2019-12-08 06:07:01

问题


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.


回答1:


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




回答2:


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)



来源:https://stackoverflow.com/questions/6161054/android-browse-audio-playlist-and-open-a-m3u-file-from-an-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!