首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MediaStore.Playlists.Members.moveItem的替代方案

MediaStore.Playlists.Members.moveItem的替代方案
EN

Stack Overflow用户
提问于 2011-11-24 14:14:17
回答 1查看 595关注 0票数 5

我一直在使用以下代码从我的Android应用程序的播放列表中删除一个项目:

代码语言:javascript
复制
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需要更改的唯一内容。是否有其他方法可以从播放列表中删除项目,并在删除的项目之后调整项目的顺序?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-08-07 17:20:38

看一下MediaStore的代码,我们得出了这个解决方案,似乎工作得很好:

代码语言:javascript
复制
/**
 * 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;
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8252878

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档