我正在尝试获取设备中的所有用户定义的播放列表。但我只获得默认播放列表。我尝试创建2个播放列表,但仍然无法检索到我创建的任何播放列表。请帮忙。我粘贴代码来创建播放列表以及检索。 编辑:仅创建播放列表有问题。我可以检索在其他音乐应用中创建的播放列表。
public void addToPlaylist(long playlistId, Context context,
List<Song> playlistTracks, String playlistName) {
int count = getPlaylistSize(playlistId, context);
Log.d("playlist size=", "" + count);
ContentValues[] values = new ContentValues[playlistTracks.size()];
for (int i = 0; i < playlistTracks.size(); i++) {
values[i] = new ContentValues();
values[i].put(MediaStore.Audio.Playlists.Members.PLAY_ORDER, i
+ count + 1);
values[i].put(MediaStore.Audio.Playlists.Members.AUDIO_ID,
playlistTracks.get(i).getAudioId());
values[i].put(MediaStore.Audio.Playlists.NAME, playlistName);
}
ContentResolver resolver = context.getContentResolver();
Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external",
playlistId);
int num = resolver.bulkInsert(uri, values);
Log.d("songs added=", "" + num); // added
resolver.notifyChange(Uri.parse("content://media"), null);
}
public void retrieveAllPlaylists(Context context) {
Uri tempPlaylistURI = MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI;
final String idKey = MediaStore.Audio.Playlists._ID;
final String nameKey = MediaStore.Audio.Playlists.NAME;
final String[] columns = { idKey, nameKey };
Cursor playListCursor = context.getContentResolver().query(
tempPlaylistURI, columns, null, null, null);
if (playListCursor != null) {
Log.d("playlist cursor count=", "" + playListCursor.getCount());
for (boolean hasItem = playListCursor.moveToFirst(); hasItem; hasItem = playListCursor
.moveToNext()) {
playlistName = playListCursor.getString(playListCursor
.getColumnIndex(nameKey));
// noOfTracks = playListCursor.getInt(playListCursor
// .getColumnIndex(tracksCountKey));
Log.d(this.getClass().getName(), "playlistname=" + playlistName // returns only default playliststhe
+ "tracks=" + noOfTracks);
playlistModel.add(new PlaylistModel(playlistName, noOfTracks));
}
}
}