Android查询系统的音频(音乐播放器的核心)

 //查询系统的音频库
public static List<MusicBean> getMusicInfo(Context context){
List<MusicBean> musicList= new ArrayList<>();
//查询音频数据库
Cursor c = context.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, MediaStore.Audio.Media.DURATION+">=?", new String[]{"20000"}, MediaStore.Audio.Media.DEFAULT_SORT_ORDER); while (c.moveToNext()){
MusicBean musicBean=new MusicBean();
musicBean.setTitle(c.getString(c.getColumnIndex(MediaStore.Audio.Media.TITLE)));
musicBean.setName(c.getString(c.getColumnIndex(MediaStore.Audio.Media.DISPLAY_NAME)));
//对未知艺术家进行判断
String singer = c.getString(c.getColumnIndex(MediaStore.Audio.Media.ARTIST));
if(singer==null || "".equals(singer) || "<unknown>".equals(singer)){
singer = "未知艺术家";
}
musicBean.setSinger(singer);
musicBean.setAlbum(c.getString(c.getColumnIndex(MediaStore.Audio.Media.ALBUM)));
musicBean.setSize(c.getLong(c.getColumnIndex(MediaStore.Audio.Media.SIZE)));
musicBean.setTime(c.getLong(c.getColumnIndex(MediaStore.Audio.Media.DURATION)));
musicBean.setUrl(c.getString(c.getColumnIndex(MediaStore.Audio.Media.DATA)));
musicList.add(musicBean); }
//关闭游标,释放资源
c.close();
return musicList;
}
上一篇:无法启动mysql服务”1067 进程意外终止”解决办法【简记】


下一篇:js手机短信按钮倒计时