我一直在使用以下代码从我的Android应用程序的播放列表中删除一个项目:
private void removeFromPlaylist(long playlistId, int loc)
{
ContentResolver resolver = getApplicationContext().getContentResolver();
Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external", playlistId);
resolver.delete(uri, MediaStore.Audio.Playlists.Members.PLAY_ORDER+" = "+loc, null);
for(int i=loc+1;i<playSongIDs.length;i++) {
MediaStore.Audio.Playlists.Members.moveItem(resolver,playlistId,i, i-1);
}
}我目前使用的是Android2.2库,这是我使用Android2.1需要更改的唯一内容。是否有其他方法可以从播放列表中删除项目,并在删除的项目之后调整项目的顺序?
发布于 2012-08-07 17:20:38
看一下MediaStore的代码,我们得出了这个解决方案,似乎工作得很好:
/**
* Convenience method to move a playlist item to a new location
* @param res The content resolver to use
* @param playlistId The numeric id of the playlist
* @param from The position of the item to move
* @param to The position to move the item to
* @return true on success
*/
private boolean moveItem(ContentResolver res, long playlistId, int from, int to) {
Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external",
playlistId)
.buildUpon()
.appendEncodedPath(String.valueOf(from))
.appendQueryParameter("move", "true")
.build();
ContentValues values = new ContentValues();
values.put(MediaStore.Audio.Playlists.Members.PLAY_ORDER, to);
return res.update(uri, values, null, null) != 0;
}https://stackoverflow.com/questions/8252878
复制相似问题