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

问题描述

我面临的一个问题,我不能由我自己处理,我从字面上检查code的每一行,但它仍然没有工作。

我的ListView拖动,从而重新presents播放列表(普通MediaStore.Audio.Playlist),并改变歌曲顺序下降监听器。

  listView.setDropListener(新DragSortListView.DropListener(){
                @覆盖
                公共无效降(INT I,诠释I2){
                    如果(playlistId!= -1){
                        布尔移动= MediaStore.Audio.Playlists.Members.moveItem(getContentResolver(),playlistId,I,I 2);
                        的System.out.println(项目移动+移动);
                    }
                }
            });

我也有contentObserver,处理光标重装。

 私有类MyContentObserver扩展ContentObserver {
    MyContentObserver(处理程序处理){
        超(处理);
    }
    @覆盖
    公共布尔deliverSelfNotifications(){
        返回true;
    }
    @覆盖
    公共无效的onChange(布尔selfChange,开放的URI){
        super.onChange(selfChange);
        的System.out.println(更新);
    }
}

当然手柄注册

  getContentResolver()registerContentObserver(Uri.parse(内容://传媒),真的,contentObserver)。

但这里有一个问题 - 移动选项总是返回true,但歌曲顺序保持不变。 4.4.4用有时,索尼的平板电脑 - - 上2.3.6移动选项不能在所有的工作,在4.4.2一切正常。我也试过这code有同样的结果。

 公共静态最终布尔移动选项(Con​​tentResolver的资源,
                                     长playlistId,从int,int值){
    URI URI = MediaStore.Audio.Playlists.Members.getContentUri(外部,
            playlistId)
            。建立在()
            .appendEn codeDPATH(将String.valueOf(从))
            .appendQueryParameter(动,真)
            。建立();
    ContentValues​​值=新ContentValues​​();
    values​​.put(MediaStore.Audio.Playlists.Members.PLAY_ORDER,到);
    返回res.update(URI,价值观,NULL,NULL)!= 0;
}


解决方案

 公共无效降(INT I,诠释I2){
    如果(playlistId!= -1){
        布尔移动= MediaStore.Audio.Playlists.Members.moveItem(getContentResolver(),playlistId,I,I 2);
        的System.out.println(项目移动+移动);        //扫描播放列表
        字符串的URL =文件://+ Environment.getExternalStorageDirectory()+/播放列表;
        URI URI = Uri.parse(URL);
        。getActivity()sendBroadcast(新意图(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,URI));
    }
}

I faced a problem I can't handle by myself, I have checked literally every single line of code, but it's still not working.

I have draggable listView, which represents a playlist (ordinary MediaStore.Audio.Playlist) and drop listener for changing order of songs.

listView.setDropListener(new DragSortListView.DropListener() {
                @Override
                public void drop(int i, int i2) {
                    if(playlistId != -1) {
                        boolean moved = MediaStore.Audio.Playlists.Members.moveItem(getContentResolver(), playlistId, i, i2);
                        System.out.println("Item moved " + moved);
                    }
                }
            });

Also I have contentObserver, which handles cursor reloading.

private class MyContentObserver extends ContentObserver {
    MyContentObserver(Handler handler) {
        super(handler);
    }
    @Override
    public boolean deliverSelfNotifications() {
        return true;
    }
    @Override
    public void onChange(boolean selfChange,  Uri uri) {
        super.onChange(selfChange);
        System.out.println("Updated");
    }
}

Of course handle is registered

getContentResolver().registerContentObserver(Uri.parse("content://media"), true, contentObserver);

But here's a problem - moveItem always returns true, but order of songs remains same. On 2.3.6 moveItem doesn't work at all, on 4.4.2 - sometimes, on sony tablet with 4.4.4 - everything works well. I also tried this code with same result

public static final 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;
}
解决方案
public void drop(int i, int i2) {
    if(playlistId != -1) {
        boolean moved = MediaStore.Audio.Playlists.Members.moveItem(getContentResolver(), playlistId, i, i2);
        System.out.println("Item moved " + moved);

        // scan playlists
        String url = "file://" + Environment.getExternalStorageDirectory() + "/Playlists";
        Uri uri = Uri.parse(url);
        getActivity().sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uri));
    }
}

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

10-20 20:15