我试图将歌曲添加到现有播放列表中,但由于某种原因,该歌曲未被添加。但是没有遇到任何错误。我在日志中检查URI,它总是给出null。我传递了播放列表ID和歌曲对象。提前谢谢。
代码:
public static void AddSongToPlaylist(SongInfoModel songInfoModel, long pID, Context context )
{
Uri pUri = MediaStore.Audio.Playlists.Members.getContentUri("external", pID);
ContentResolver resolver = context.getContentResolver();
ContentValues values = new ContentValues();
values.put(MediaStore.Audio.Playlists.Members.AUDIO_ID, songInfoModel.getSongID());
values.put(MediaStore.Audio.Playlists.Members.TITLE, songInfoModel.getSongName());
values.put(MediaStore.Audio.Playlists.Members.ARTIST, songInfoModel.getArtistName());
values.put(MediaStore.Audio.Playlists.Members.DURATION, songInfoModel.getDuration());
resolver.insert(pUri,values);
resolver.notifyChange(Uri.parse("content://media"), null);
Log.i("URI:",resolver.insert(pUri, values)+"");
}
传递pID和歌曲对象:
Playlistadapter = new ListPlayListAdapter(finalDialogPlaylist, getContext(), new ListPlayListAdapter.ItemClickListener() {
@Override
public void onClickListener(PlaylistsModel playlistsModel, int position) {
Playlists.AddSongToPlaylist(song,playlistsModel.getPlaylistID(),getContext());
}
});
答案 0 :(得分:0)
您使用的是错误的参数。
所需要的只是如下:
Uri newuri = MediaStore.Audio.Playlists.Members.getContentUri(
"external", playlist_id);
ContentResolver resolver = context.getContentResolver();
ContentValues values = new ContentValues();
values.put(MediaStore.Audio.Playlists.Members.PLAY_ORDER, pos);
values.put(MediaStore.Audio.Playlists.Members.AUDIO_ID, audio_id);
values.put(MediaStore.Audio.Playlists.Members.PLAYLIST_ID,
playlist_id);