这是我写的获取信息得方法
public List<Mp3Info> getMp3Infos(String c){
Cursor cursor = null;
if(c.equals("songs")){//songs list
cursor = getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
null, null, null, MediaStore.Audio.Media.DEFAULT_SORT_ORDER);
}
else if(c.equals("artists")){//artists list
cursor = getContentResolver().query(MediaStore.Audio.Artists.EXTERNAL_CONTENT_URI,
null, null, null, MediaStore.Audio.Artists.DEFAULT_SORT_ORDER);
}
else if(c.equals("albums")){//albums list
cursor = getContentResolver().query(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI,
null, null, null, MediaStore.Audio.Albums.DEFAULT_SORT_ORDER);
}
else if(c.equals("playlist")){//play list
cursor = getContentResolver().query(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,
null, null, null, MediaStore.Audio.Playlists.DEFAULT_SORT_ORDER);
}
List<Mp3Info> mp3Infos = new ArrayList<Mp3Info>();
int i;
for(i = 0, cursor.moveToFirst(); i < cursor.getCount(); ++i){
Mp3Info mp3info = new Mp3Info();
String title = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.TITLE));
String album = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM));
String artist = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST));
long duration = cursor.getLong(cursor.getColumnIndex(MediaStore.Audio.Media.DURATION));
int isMusic = cursor.getInt(cursor.getColumnIndex(MediaStore.Audio.Media.IS_MUSIC));
if(isMusic != 0){
mp3info.title = title;
mp3info.album = album;
mp3info.artist = artist;
mp3info.duration = duration;
mp3Infos.add(mp3info);
}
cursor.moveToNext();
}
return mp3Infos;
}
使用cursor的时候不需要循环吧?
但是我SD卡中有2个音频文件,却只显示一条信息。