Android Java - 从特定文件夹中读取音乐

时间:2023-02-06 10:51:35

I'm following a tutorial and have modified it to come up with this:

我正在关注一个教程,并对其进行了修改以得出这个:

    String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0";

    String[] proj = { MediaStore.Audio.Media._ID,
            MediaStore.Audio.Media.DATA, 
            MediaStore.Audio.Media.DISPLAY_NAME};

    Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
    String sortOrder = MediaStore.Audio.Media.DISPLAY_NAME + " ASC";

    musiccursor = getContentResolver().query(uri, proj, selection, null, sortOrder);

The above code will read all the music on my external. Is there a way for me to specify a specific a folder to read music from? I'm guessing I'll have to change the uri since that is pointing to my external, I think??

上面的代码将读取我外部的所有音乐。有没有办法让我指定一个特定的文件夹来读取音乐?我猜我必须改变uri,因为那是指向我的外部,我想?

1 个解决方案

#1


1  

Yes you can do by

是的,你可以做到

musiccursor = getContentResolver().query( uri,
                proj,
                MediaStore.Audio.Media.DATA + " like ? ",
                new String[] {"%myfolder%"},
                sortOrder);

#1


1  

Yes you can do by

是的,你可以做到

musiccursor = getContentResolver().query( uri,
                proj,
                MediaStore.Audio.Media.DATA + " like ? ",
                new String[] {"%myfolder%"},
                sortOrder);