代码如下
1 public static List<music> getAllMusic(Context context){ 2 musics.clear(); 3 4 Uri uri=MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; 5 /** 6 * public String name;//歌曲名 7 public String author;//歌手 8 public String path;//路径
还可以获取其他信息 9 */ 10 String[] projection = { MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media.ARTIST, 11 MediaStore.Audio.Media.DATA }; 12 Cursor cursor = context.getContentResolver().query(uri, projection, null, null, null); 13 while (cursor.moveToNext()) { 14 music m=new music(); 15 m.author=cursor.getString(1); 16 m.name=cursor.getString(0); 17 m.path=cursor.getString(2); 18 musics.add(m); 19 } 20 21 return musics; 22 }
music的bean类
1 public class music { 2 public String path; 3 public String name; 4 public String author; 5 6 }