将媒体从特定目录加载到路径 - android

时间:2016-11-02 12:00:57

标签: android media-player

我已通过此命令在设备存储中创建了一个目录:

File zenglishSubDirectoryDownloadByLevel = new File(Environment.getExternalStorageDirectory() + "/zenglish/sounds/level_1");
                    if(!zenglishSubDirectoryDownloadByLevel.exists()){
                        zenglishSubDirectoryDownloadByLevel.mkdirs();
                    }

这很好。现在我想用适配器在/zenglish/sounds/level_1路径中加载音乐。所以我使用了这段代码:

File f = new File(Environment.getExternalStorageDirectory() + "/zenglish/sounds/level_1");
Uri soundURI = Uri.fromFile(f);
Log.e("sound uri","=>"+soundURI.getPath());
String[] projection = new String[]{
        MediaStore.Audio.Media.TITLE,
        MediaStore.Audio.Media.ALBUM,
        MediaStore.Audio.Media.ALBUM_ID,
        MediaStore.Audio.Media.ARTIST,
        MediaStore.Audio.Media.DURATION,
        MediaStore.Audio.Media.DATA,
};
Cursor cursor = getContext().getContentResolver().query(
       // MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, // is ok
        soundURI, // is empty
        projection,
        MediaStore.Audio.Media.IS_MUSIC + "=1",
        null,
        "LOWER(" + MediaStore.Audio.Media.ARTIST + ") ASC, " +
                "LOWER(" + MediaStore.Audio.Media.ALBUM + ") ASC, " +
                "LOWER(" + MediaStore.Audio.Media.TITLE + ") ASC"
);
if (cursor == null) {
    return Collections.emptyList();
}

所以,我的问题是soundURI总是为空(光标为空)但MediaStore.Audio.Media.EXTERNAL_CONTENT_URI运行良好并加载我设备存储中的所有音频文件。如何将/zenglish/sounds/level_1的音乐加载到soundURI

正确的道路是什么?

0 个答案:

没有答案