1 //查询系统的音频库 2 public static List<MusicBean> getMusicInfo(Context context){ 3 List<MusicBean> musicList= new ArrayList<>(); 4 //查询音频数据库 5 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); 6 7 while (c.moveToNext()){ 8 MusicBean musicBean=new MusicBean(); 9 musicBean.setTitle(c.getString(c.getColumnIndex(MediaStore.Audio.Media.TITLE))); 10 musicBean.setName(c.getString(c.getColumnIndex(MediaStore.Audio.Media.DISPLAY_NAME))); 11 //对未知艺术家进行判断 12 String singer = c.getString(c.getColumnIndex(MediaStore.Audio.Media.ARTIST)); 13 if(singer==null || "".equals(singer) || "<unknown>".equals(singer)){ 14 singer = "未知艺术家"; 15 } 16 musicBean.setSinger(singer); 17 musicBean.setAlbum(c.getString(c.getColumnIndex(MediaStore.Audio.Media.ALBUM))); 18 musicBean.setSize(c.getLong(c.getColumnIndex(MediaStore.Audio.Media.SIZE))); 19 musicBean.setTime(c.getLong(c.getColumnIndex(MediaStore.Audio.Media.DURATION))); 20 musicBean.setUrl(c.getString(c.getColumnIndex(MediaStore.Audio.Media.DATA))); 21 musicList.add(musicBean); 22 23 } 24 //关闭游标,释放资源 25 c.close(); 26 return musicList; 27 }