我想建立一個音樂播放器應用程序,我想以一首歌曲添加到playlist.Here添加一個功能是代碼:插入歌曲播放列表返回null
public static void addToPlaylist(ContentResolver resolver,SongDetails songDetails,int playlistId) {
String[] cols = new String[] {
"count(*)"
};
Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external", playlistId);
Cursor cur = resolver.query(uri, cols, null, null, null);
cur.moveToFirst();
final int base = cur.getInt(0);
cur.close();
ContentValues values = new ContentValues();
values.put(MediaStore.Audio.Playlists.Members.PLAY_ORDER, Integer.valueOf(base + songDetails.getId()));
values.put(MediaStore.Audio.Playlists.Members.AUDIO_ID, songDetails.getId());
values.put(MediaStore.Audio.Playlists.Members.DISPLAY_NAME, songDetails.getSongTitle());
values.put(MediaStore.Audio.Playlists.Members.ARTIST, songDetails.getArtistName());
values.put(MediaStore.Audio.Playlists.Members.DATA, songDetails.getSongData());
Log.i("URI:",resolver.insert(uri, values)+"");
}
和日誌中我總是得到:
URI: null
這意味着該歌曲不被添加到playlist.Does有人有,爲什麼不添加任何歌曲的想法?
你不想在''PLAY_ORDER'基地+ 1'? –
它也返回null – Khafaga
你在哪裏設置了songDetails'id'? –