0

Ok, so I am a newbie with android and on the site itself. I am trying to retrieve album art for my music player.

public void getSonglist(){
    Songs song;
    ContentResolver songResolver = getContentResolver();
    Uri songUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
    Uri artUri;
    Cursor songCursor = songResolver.query(songUri, null, null, null, null);
    final Uri ART_CONTENT_URI = Uri.parse("content://media/external/audio/albumart");
if(songCursor.moveToFirst()){
    do{ song = new Songs("","",0);
        albumID = songCursor.getLong(songCursor.getColumnIndex(MediaStore.Audio.Media.ALBUM_ID));
        song.setTitle(songCursor.getString(songCursor.getColumnIndex(MediaStore.Audio.Media.TITLE)));
        song.setArtist(songCursor.getString(songCursor.getColumnIndex(MediaStore.Audio.Media.ARTIST)));
        song.set_Id(songCursor.getLong(songCursor.getColumnIndex(MediaStore.Audio.Media._ID)));
        artUri = ContentUris.withAppendedId(ART_CONTENT_URI, albumID);
        AlbumArt = null;

        try {
            AlbumArt = (MediaStore.Images.Media.getBitmap(getContentResolver(), artUri));
        } catch (Exception exception) {
            // log error
        }
        song.setAlbumArt(AlbumArt);
        songlist.add(song);
    }while(songCursor.moveToNext());
}

}

The problem here is that though the code has no errors, I have a large number of songs on my device (Around 900) and the app runs out of memory while trying yo load the album art. (E/art: Throwing OutOfMemoryError "Failed to allocate a 1000012 byte allocation with 331252 free bytes and 323KB until OOM")

Can someone tell me another,better way to get the album art? (Please support your answer with code if possible).

Community
  • 1
  • 1
Aditya G.
  • 3
  • 3
  • http://stackoverflow.com/questions/12583419/implement-endless-scroll-on-listview – koutuk Dec 17 '15 at 09:40
  • http://stackoverflow.com/questions/8586638/android-list-view-that-loads-data-dynamically-based-on-scroll-position – koutuk Dec 17 '15 at 09:41

0 Answers0