0

I've been developing an android music player and I would like to load the cover image which each mp3 tag has. I previously used the following code to extract the image but, when the list view is starts scrolling it gives a lot of errors and the app crashes at random times. The code is as following.

MediaMetadataRetriever retrieve = new MediaMetadataRetriever();
retrieve.setDataSource(songsList.get(songIndex).get("songPath"));

byte [] data = mmr.getEmbeddedPicture();

This throws an error saying the following message and at random points the application crashes.

getEmbeddedPicture: Call to getEmbeddedPicture failed

So I used the glide library to load the images using the following code.

Glide.with(parent.getContext()).load(currSong.getPath())
            .placeholder(R.drawable.default_img).into(holder.albumImage);

The thing is I pass the song path to the load function but doesn't load any image to it! I logged the path and it shows the correct path to the mp3 file.

How can I load the images using the Glide library! If there is a tutorial on this, please be kind enough to let me know.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Imesh Chandrasiri
  • 5,558
  • 15
  • 60
  • 103
  • This link shows Glide Example. Answer is quite old so it may not work now. http://stackoverflow.com/questions/1954434/cover-art-on-android – Vivek Mishra Dec 28 '16 at 12:48

1 Answers1

0

I did the following to retrieve and set the image in the list.

To retrieve album art for the song:- This is the query

final Cursor mCursor = getContentResolver().query(
                MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
                new String[]{MediaStore.Audio.Media.DISPLAY_NAME, MediaStore.Audio.Media.DATA, MediaStore.Audio.Media.ALBUM_ID}, null, null,
                "LOWER(" + MediaStore.Audio.Media.TITLE + ") ASC");

To capture URI

long album_id=mCursor.getLong(mCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM_ID));
Uri sArtworkUri = Uri.parse("content://media/external/audio/albumart");
Uri albumArtUri = ContentUris.withAppendedId(sArtworkUri, album_id);

And then to set in list via Adapter

Uri uri=Uri.parse(data.get(position).getAlbum_art());
        try {
            bitmap =  MediaStore.Images.Media.getBitmap(ctx.getContentResolver(), uri);
            holder.image.setImageBitmap(bitmap);
        } catch (IOException e) {
            e.printStackTrace();
        }
Vivek Mishra
  • 5,669
  • 9
  • 46
  • 84