替代MediaStore.Playlists.Members.moveItem [英] Alternative to MediaStore.Playlists.Members.moveItem

查看:222
本文介绍了替代MediaStore.Playlists.Members.moveItem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用下面的code,除去我的Andr​​oid应用程序从播放列表中的项目:

I've been using the following code to remove an item from a playlist in my Android app:

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);
    }
}

我目前使用了Android 2.2库,这是我需要改变使用Android 2.1的唯一的事情。是否有从播放列表删除项目和删除的一个后调整项目的顺序的另一种方法

I'm currently using the Android 2.2 library and this is the only thing that I need to change to use Android 2.1. Is there an alternate method for removing an item from a playlist and adjusting the order of the items after the deleted one?

推荐答案

看MediaStore的code,我们这个解决方案,似乎很好地工作就出来了:

looking at the code of the MediaStore we came out with this solution that seems to work fine:

/**
 * 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;
}

这篇关于替代MediaStore.Playlists.Members.moveItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆