private List<Album> getAlbums() {
Cursor cur = managedQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, null, null, null);
List<Album> albums = new ArrayList<Album>();
if (cur.moveToFirst()) {
do {
int albumIdIndex = cur.getColumnIndex(MediaStore.Audio.Media.ALBUM_ID);
int albumIndex = cur.getColumnIndex(MediaStore.Audio.Media.ALBUM);
int artistIndex = cur.getColumnIndex(MediaStore.Audio.Media.ARTIST);
int albumId = cur.getInt(albumIdIndex);
String name = cur.getString(albumIndex);
String artist = cur.getString(artistIndex);
LogUtil.i(TAG, "albumid= " + albumId + ", album= " + name + ", artist=" + artist);
Album album = new Album(albumId, name, artist);
if (!albums.contains(album)) {
albums.add(album);
}
} while (cur.moveToNext());
}
return albums;
}
我知道我可以使用以下代码来获得实际的艺术品,但我需要缩略图,因为如果我在列表活动中使用完整图像,我的内存就会不足:
Uri sArtworkUri = Uri.parse("content://media/external/audio/albumart");
Uri uri = ContentUris.withAppendedId(sArtworkUri, album_id);
我看到这个帖子:
Android media thumbnails. Serious issues?
但是我没有imageId,只有albumid,所以我觉得这没用。