views:

354

answers:

2

I have a list of albums which I got using this:

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;
 }

I use this list of albums in a ListActivity, but I also want to get the thumbnails of the Albums.

I know I can use the following code to get the actual artwork, but I need the thumbnails because I get Out Of Memory if I use the full images in a List Activity:

Uri sArtworkUri = Uri.parse("content://media/external/audio/albumart");
Uri uri = ContentUris.withAppendedId(sArtworkUri, album_id);

I saw this post: http://stackoverflow.com/questions/2902232/android-media-thumbnails-serious-issues But I do not have the imageId, only the albumid, so I don't think it helps.

+2  A: 

Get each album art, create a new version of it using Bitmap.createScaledBitmap(), use that, recycle() the old bitmap to make memory go away, move to next image. Keep a HashMap or something to make sure you don't load the same album art twice or more (More than one track will have the same Album art id, cache it.

Should work well. (Works for me)

Moncader
This was the approach I took but I think there is a URI for album art too: content://media/external/audio/albumart_thumb.I am actually stuck on writing Bitmaps to the URI content://media/external/audio/albumart at the moment. I am getting FileNotFoundExceptions when I use this code: Uri artworkUri = Uri.parse("content://media/external/audio/albumart");Uri uri = ContentUris.withAppendedId(artworkUri, album.getId());OutputStream outStream = getContentResolver().openOutputStream(uri);bmp.compress(Bitmap.CompressFormat.JPEG, 50, outStream);
timothyjc
Oh - I figured out the writing albumart part from here: http://www.netmite.com/android/mydroid/packages/apps/Music/src/com/android/music/MusicUtils.java
timothyjc
A: 

Could you post some code on this i want to learn how to do this to but iam a little to noobish to figure it out please?

Techy_Dev
Look at the getArtworkQuick method from here http://www.netmite.com/android/mydroid/packages/apps/Music/src/com/android/music/MusicUtils.java.
timothyjc
Thank you for your help.
Techy_Dev