cover art on android

Uri sArtworkUri = Uri.parse("content://media/external/audio/albumart");
Uri uri = ContentUris.withAppendedId(sArtworkUri, album_id);
ContentResolver res = context.getContentResolver();
InputStream in = res.openInputStream(uri);
Bitmap artwork = BitmapFactory.decodeStream(in);

More complete sample code can be found in Android Music player source here https://github.com/android/platform_packages_apps_music/blob/master/src/com/android/music/MusicUtils.java method getArtworkQuick.


I don't know why everybody is making it so complicated you can use Glide to achieve this in simplest and efficient way with just 1 line of code

Declare this path in App Constants -

final public static Uri sArtworkUri = Uri
                .parse("content://media/external/audio/albumart");

Get Image Uri using Album ID

Uri uri = ContentUris.withAppendedId(PlayerConstants.sArtworkUri,
                        listOfAlbums.get(position).getAlbumID());

Now simply display album art using uri :-

    Glide.with(context).load(uri).placeholder(R.drawable.art_default).error(R.drawable.art_default)
                    .crossFade().centerCrop().into(holder.albumImage);

Glide will handle caching, scaling and lazy loading of images for you.

Hope it help somebody.


You can use

MediaMetadataRetriever

class and get track info i.e. Title,Artist,Album,Image

Bitmap GetImage(String filepath)              //filepath is path of music file
{
 Bitmap image;

MediaMetadataRetriever mData=new MediaMetadataRetriever();
mData.setDataSource(filePath);
     try{
            byte art[]=mData.getEmbeddedPicture();
            image=BitmapFactory.decodeByteArray(art, 0, art.length);
        }
    catch(Exception e)
        { 
           image=null;
        }
    return image;
}

Here i can attach one function that is return album art from media store .

Here in function we just have to pass the album_id which we get from Media store .

public Bitmap getAlbumart(Long album_id) 
   {
        Bitmap bm = null;
        try 
        {
            final Uri sArtworkUri = Uri
                .parse("content://media/external/audio/albumart");

            Uri uri = ContentUris.withAppendedId(sArtworkUri, album_id);

            ParcelFileDescriptor pfd = context.getContentResolver()
                .openFileDescriptor(uri, "r");

            if (pfd != null) 
            {
                FileDescriptor fd = pfd.getFileDescriptor();
                bm = BitmapFactory.decodeFileDescriptor(fd);
            }
    } catch (Exception e) {
    }
    return bm;
}

Based on your comments to others, it seems like your question is less about Android and more about how to get album art in general. Perhaps this article on retrieving album art from Amazon will be helpful. Once you have a local copy and store it as Nick has suggested, I believe you should be able to retrieve it the way Fudgey suggested.