这是我的代码。它是从所有目录中获取歌曲,但我想只从特定的文件夹。我怎么做呢
'
私有空读取媒体文件(){内容解析器内容解析器= context.getContentResolver();
Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
String music = MediaStore.Audio.Media.IS_MUSIC + " != 0";
Log.d("this123",music.toString());
String sort = MediaStore.Audio.Media.ALBUM + " ASC";
String[] projection = {MediaStore.Audio.Albums.ALBUM_ID, MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media.DATA};
Cursor cursor = contentResolver.query(uri,projection,music,null,sort);
if(cursor != null) {
Msg.log(String.valueOf(cursor.getCount()));
if(cursor.getCount() > 0) {
while(cursor.moveToNext()) {
@SuppressLint("Range") String path = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DATA));
@SuppressLint("Range") String title = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.TITLE));
@SuppressLint("Range") String albumid = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Albums.ALBUM_ID));
mediaListModel = new MediaListModel(Long.parseLong(albumid),path,title);
mediaListModelArrayList.add(mediaListModel);
}
}`
2条答案
按热度按时间yiytaume1#
您可以使用以下方法实现仅从特定文件夹中提取歌曲的目标:
***/mnt/sdcard/Music/SomeArtist/***是您只想从那里获取歌曲的位置。这会将您的managedQuery结果限制到.../SomeArtist/目录。
jchrr9hc2#
试试这个...