我已通过此命令在设备存储中创建了一个目录:
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
?
正确的道路是什么?