0

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?

NewGradDev
  • 1,004
  • 6
  • 16
  • 35

1 Answers1

3

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);
tachyonflux
  • 20,103
  • 7
  • 48
  • 67
  • Could you please add some explanation to your post on why this should fix the OP's problem? Thanks! – hichris123 Feb 06 '15 at 03:38
  • Uh, because that is a filepath, not a URI. I'm actually not even sure what `Uri.parseUri` is. It's clearly not any standard implementation of the Uri class. An alternate solution would be: `Picasso.with(this).load(Uri.parse("file://" + albumArtPath)).into(imageView);` – tachyonflux Feb 06 '15 at 04:07
  • Perfect, thanks! :) Mind [edit]ing that into your answer too? – hichris123 Feb 06 '15 at 04:08
  • Perfect. Adding `new File(albumArtPath)` fixed it for me. Thanks! – NewGradDev Feb 06 '15 at 05:34