gpt4 book ai didi

android - MediaStore.Playlists.Members.moveItem 的替代品

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:18:58 26 4
gpt4 key购买 nike

我一直在使用以下代码从我的 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);
}
}

我目前使用的是 Android 2.2 库,这是我唯一需要更改才能使用 Android 2.1 的东西。是否有替代方法从播放列表中删除项目并调整删除项目之后的项目顺序?

最佳答案

查看 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;
}

关于android - MediaStore.Playlists.Members.moveItem 的替代品,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8252878/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com