NewGradDev
NewGradDev

Reputation: 1034

Android Album Art from MediaStore (and Picasso)

Trying to retrieve the path to the album art for each album in MediaStore. I'm retrieving my cursor like this:

String[] projection = new String[] {MediaStore.Audio.Albums._ID,
                                    MediaStore.Audio.Albums.ALBUM_ART,
                                    MediaStore.Audio.Albums.ALBUM,
                                    MediaStore.Audio.Albums.ARTIST};

// Returns a new CursorLoader
return new CursorLoader(getActivity(),
                        MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI,
                        projection,
                        null,
                        null,
                        MediaStore.Audio.Albums.ALBUM + " ASC");

Which returns a valid cursor with all the unique albums and their respective artists, album names, ids, and album art paths. However, I can't figure out how to use the album art paths. Here's an example of a path that I get from the ALBUM_ART column:

/storage/emulated/0/Android/data/com.android.providers.media/albumthumbs/1420524553603

I'm trying to pass this on to Picasso but it throws back an error. Here's how I'm doing it:

Picasso.with(mContext).load(Uri.parseUri(albumArtPath)).into(imageView);

where albumArtPath is the path that I get from the cursor (see above). I end up with a blank ImageView, so nothing is basically getting loaded. How do I get Picasso to work with Mediastore album art paths?

Upvotes: 0

Views: 1980

Answers (1)

tachyonflux
tachyonflux

Reputation: 20211

That is a filepath, not a URI.

Any of these would work:

Picasso.with(mContext).load(new File(albumArtPath)).into(imageView);
Picasso.with(mContext).load(Uri.parse("file://" + albumArtPath)).into(imageView);
Picasso.with(mContext).load(Uri.fromFile(new File(albumArtPath))).into(imageView);

Upvotes: 3

Related Questions