I'm working on a music player for android. I introduced the playlist feature in which users can create playlist and add songs to playlist. So, in the playlist, I have implemented the drag and drop feature (moving song from one position to other by dragging them across the list). This feature works fine. But the problem I'm facing is after dragging and dropping, I can't update the playlist database(of mediastore).
EDIT: I noticed that other music players show the updated playlist but my app doesn't update the playlist.
The code I'm using:
public static void trackMoved(int fromPosition, int toPosition) {
Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external",
pID)
.buildUpon()
.appendEncodedPath(String.valueOf(fromPosition))
.appendQueryParameter("move", "true")
.build();
ContentValues values = new ContentValues();
values.put(MediaStore.Audio.Playlists.Members.PLAY_ORDER, toPosition);
cr.update(uri, values, null, null) ;
}
I found the solution actually I had to sort in according to play order -_-.