Home » Android » android – How can I display Album Art using MediaStore.Audio.Albums.ALBUM_ART?

android – How can I display Album Art using MediaStore.Audio.Albums.ALBUM_ART?

Posted by: admin May 14, 2020 Leave a comment


I’m trying to build a MP3 player and I want the ImageView to display the album art of respective songs. I’ve tried the following, but it doesn’t work.

albumcover = (ImageView) findViewById(R.id.cover);

String coverPath = songsList.get(songIndex).get(MediaStore.Audio.Albums.ALBUM_ART);
Drawable img = Drawable.createFromPath(coverPath);

When I try to play the songs, all I get is a blank screen in the ImageView.

How to&Answers:

Here’s how I get album art for a song:

Cursor cursor = getContentResolver().query(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, 
                new String[] {MediaStore.Audio.Albums._ID, MediaStore.Audio.Albums.ALBUM_ART}, 
                MediaStore.Audio.Albums._ID+ "=?", 
                new String[] {String.valueOf(albumId)}, 

if (cursor.moveToFirst()) {
    String path = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Albums.ALBUM_ART));
    // do whatever you need to do

albumId refers to MediaStore.Audio.Media.ALBUM_ID for that song.

If you’re are looking for album art for a particular song (rather than in a list of albums), as far as I know it’s a two-stage process since ALBUM_ART is a property of MediaStore.Audio.Albums and is not available directly as song metadata.


If you have album ID you get Album Image uri :-

final public static Uri sArtworkUri = Uri

Uri uri = ContentUris.withAppendedId(PlayerConstants.sArtworkUri,

And if you have a Image uri you can use any of the image loader Glide, Picaso, UIL to display images .


you can write your own image loader

public Bitmap getAlbumart(Context context, Long album_id) {
    Bitmap albumArtBitMap = null;
    BitmapFactory.Options options = new BitmapFactory.Options();
    try {

        final Uri sArtworkUri = Uri

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

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

        if (pfd != null) {
            FileDescriptor fd = pfd.getFileDescriptor();
            albumArtBitMap = BitmapFactory.decodeFileDescriptor(fd, null,
            pfd = null;
            fd = null;
    } catch (Error ee) {
    } catch (Exception e) {

    if (null != albumArtBitMap) {
        return albumArtBitMap;
    return getDefaultAlbumArtEfficiently(context.getResources());

public Bitmap getDefaultAlbumArtEfficiently(Resources resource) {

    if (defaultBitmapArt == null) {

        defaultBitmapArt = decodeSampledBitmapFromResource(resource,
                R.drawable.default_album_art, UtilFunctions
                        .getUtilFunctions().dpToPixels(85, resource),
                UtilFunctions.getUtilFunctions().dpToPixels(85, resource));

    return defaultBitmapArt;


 ContentResolver musicResolve = getContentResolver();
    Uri smusicUri = android.provider.MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI;
    Cursor music =musicResolve.query(smusicUri,null         //should use where clause(_ID==albumid)
        ,null, null, null);

    music.moveToFirst();            //i put only one song in my external storage to keep things simple
    int x=music.getColumnIndex(android.provider.MediaStore.Audio.Albums.ALBUM_ART);
        String thisArt = music.getString(x);

     Bitmap bm= BitmapFactory.decodeFile(thisArt);
        ImageView image=(ImageView)findViewById(R.id.image);


This method return ArrayList with song path and album art.

public static ArrayList<CommonModel> getAllMusicPathList(Context context) {
    ArrayList<CommonModel> musicPathArrList = new ArrayList<>();
    Uri songUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;

    Cursor cursorAudio = context.getContentResolver().query(songUri, null, null, null, null);
    if (cursorAudio != null && cursorAudio.moveToFirst()) {

        Cursor cursorAlbum;
        if (cursorAudio != null && cursorAudio.moveToFirst()) {

            do {
                Long albumId = Long.valueOf(cursorAudio.getString(cursorAudio.getColumnIndex(MediaStore.Audio.Media.ALBUM_ID)));
                cursorAlbum = context.getContentResolver().query(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI,
                        new String[]{MediaStore.Audio.Albums._ID, MediaStore.Audio.Albums.ALBUM_ART},
                        MediaStore.Audio.Albums._ID + "=" + albumId, null, null);

                    if(cursorAlbum != null && cursorAlbum.moveToFirst()){
                        String albumCoverPath = cursorAlbum.getString(cursorAlbum.getColumnIndex(MediaStore.Audio.Albums.ALBUM_ART));
                        String data = cursorAudio.getString(cursorAudio.getColumnIndex(MediaStore.Audio.Media.DATA));
                        musicPathArrList.add(new CommonModel(data,albumCoverPath ,false));

                 } while (cursorAudio.moveToNext());
    return musicPathArrList;

this is CommonModel .

public class CommonModel {

private String path;
private boolean selected;

public String getAlbumCoverPath() {
    return albumCoverPath;

public void setAlbumCoverPath(String albumCoverPath) {
    this.albumCoverPath = albumCoverPath;

private String albumCoverPath;

public CommonModel(String path, String albumCoverPath, boolean b) {
    this.path = path;

public String getPath() {
    return path;

public void setPath(String path) {
    this.path = path;

public boolean getSelected() {
    return selected;

public void setSelected(boolean selected) {
    selected = selected;


You should use Uri.parse(“content://media/external/audio/albumart”); to query the albumart. the 1st answer may get exception on some phone (at least mine)


The below code worked for me. I know it has been answered already, it may be useful for someone checking for reference.

 public void getAlbumArt() {
    try {
        ContentResolver cr = getContentResolver();
        Uri uri = MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI;

        Cursor cursor = cr.query(uri, null, null, null, null);

        if (cursor != null && cursor.moveToFirst()) {
            int albumart = cursor.getColumnIndex(MediaStore.Audio.Albums.ALBUM_ART);
            do {
                String Albumids = cursor.getString(albumart);

            } while (cursor.moveToNext());
    } catch (NumberFormatException e){
public void getSelectedPath(){
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            String path= String.valueOf(listView.getItemAtPosition(i));

                ImageView imgv=(ImageView)view.findViewById(R.id.imageView);

                Drawable image=Drawable.createFromPath(path);
                ImageView imgview=(ImageView)view.findViewById(R.id.imageView);


for complete code visit http://vasistaguru.blogspot.com/2017/02/get-albumart-and-trackname-using.html


Example Code

public static Uri getAlbumArtUri(long albumId) {
    return ContentUris.withAppendedId(Uri.parse("content://media/external/audio/albumart"), albumId);

ArrayList<Uri> albumArtUris = new ArrayList<>();
Cursor cursor = getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, new String[]{"album_id"}, null, null, null);
do {
    long ablumId = cursor.getLong(cursor.getColumnIndexOrThrow("album_id"));
} while (cursor.moveToNext());