I'm working on playlist in my audio player. I have return a code to add songs to playlist. The code works fine, but i have a small problem though. The problem is if I add a single song to playlist, two copies of the same song are added. It is like, if I add song A to playlist and then I open the playlist to which I added song A, I can see two copies of song A in there.
Code:
public static void AddSongToPlaylist(long songID, long pID, Context context ){
Uri pUri = MediaStore.Audio.Playlists.Members.getContentUri("external", pID);
ContentResolver resolver = context.getContentResolver();
ContentValues values = new ContentValues();
String[] cols = new String[] {
"count(*)"
};
Cursor cur = resolver.query(pUri, cols, null, null, null);
cur.moveToFirst();
final int base = cur.getInt(0)+1;
cur.close();
values.put(MediaStore.Audio.Playlists.Members.PLAY_ORDER,base);
values.put(MediaStore.Audio.Playlists.Members.AUDIO_ID, songID);
resolver.insert(pUri,values);
resolver.notifyChange(Uri.parse("content://media"), null);
Log.i("URI:",resolver.insert(pUri, values)+"");
Toast.makeText(context, "Song Added", Toast.LENGTH_SHORT).show();
Log.i("Song ID:", String.valueOf(songID));
}