获取SD卡音乐文件

private ArrayList<Music> queryMusics() {
ArrayList<Music> musiclistResult = new ArrayList<Music>();
ContentResolver cr = this.getContentResolver();
Cursor musics = cr.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
new String[] {
MediaStore.Audio.Media._ID, // int
MediaStore.Audio.Media.TITLE,
MediaStore.Audio.Media.ARTIST,
MediaStore.Audio.Media.ALBUM,
MediaStore.Audio.Media.DURATION,
MediaStore.Audio.Media.DATA, // String
MediaStore.Audio.Media.DISPLAY_NAME, // String
MediaStore.Audio.Media.MIME_TYPE // String
},
MediaStore.Audio.Media.IS_MUSIC + " = 1 AND "
+ MediaStore.Audio.Media.DURATION + " > 10000",
null,
MediaStore.Audio.Media.DEFAULT_SORT_ORDER);
Log.d("", "musics : " + musics.getCount());


musics.moveToFirst();
while (!musics.isAfterLast()) {
Music temp = new Music();
temp._ID = musics.getInt(musics.getColumnIndex(MediaStore.Audio.Media._ID));
temp.ALBUM = musics.getString(musics.getColumnIndex(MediaStore.Audio.Media.ALBUM));
temp.ARTIST = musics.getString(musics.getColumnIndex(MediaStore.Audio.Media.ARTIST));
temp.DATA = musics.getString(musics.getColumnIndex(MediaStore.Audio.Media.DATA));
temp.DURATION = musics.getLong(musics.getColumnIndex(MediaStore.Audio.Media.DURATION));
temp.TITLE = musics.getString(musics.getColumnIndex(MediaStore.Audio.Media.TITLE));
temp.isExist = true;


musiclistResult.add(temp);
musics.moveToNext();
}
musics.close();
return musiclistResult;
}
/**
* 音乐的信息

* @author BabyBeaR
*/
@SuppressWarnings("unused")
private class Music {
int _ID;
long DURATION;
boolean isExist;
String TITLE, ARTIST, ALBUM, DATA;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值