2

Not sure how many people here are familiar with the Android Universal Music Player but I am having issue with displaying an album in the MediaItemViewHolder.java file.

So here is a basic structure after my modifications:

// image view for the album cover
holder.mImageView = (ImageView) convertView.findViewById(R.id.play_eq);

// get the album art url
String artUrl = description.getIconUri().toString();
Bitmap art;
AlbumArtCache cache = AlbumArtCache.getInstance();
art = cache.getIconImage(artUrl);
....
if (cachedState == null || cachedState != state) {
    switch (state) {
    case STATE_PLAYABLE:
         // display the album cover
         holder.mImageView.setImageBitmap(art);
         break;
....

This correctly displays the album cover. However, it is initially blank. Once the user clicks on an item, the image is displayed.

Screenshot #1 : Once the app is loaded and user did not click on any item:

enter image description here

Screenshot #2 : Once the user click on the item to play the song

enter image description here

I am not really sure what is causing the album to be initially blank. Looking at the AlbumArtCache.java I can't see any restrictions about OnClickListener that can cause this.

Any suggestions how to resolve this issue?

Rain Man
  • 1,163
  • 2
  • 16
  • 49

1 Answers1

1

cache.getIconImage(url) does not actually fetch the url and store it in the cache. It returns the current value or null. Instead you have to call AlbumArtCache#fetch(String url, FetchListener listener)

A good prototype of this is in FullScreenPlayerActivity#fetchImageAsync(MediaDescription description)

Here is what you could do in a method when the item is playable.

AlbumArtCache cache = AlbumArtCache.getInstance();
Bitmap art = cache.getIconImage(url);
if (art == null) {
  cache.fetch(url, new AlbumArtCache.FetchListener() {
            @Override
            public void onFetched(String artUrl, Bitmap bitmap, Bitmap icon) {
                if (artUrl.equals(url)) {
                    holder.mImageView.setImageBitmap(icon);
                }
            }
        });
} else {
    holder.mImageView.setImageBitmap(bitmap);
}
Nagesh Susarla
  • 1,660
  • 10
  • 10
  • @nagesh-susaria I attempted to give this a try on my local copy but I am getting something like this: https://drive.google.com/file/d/0BycOIcYbBvF_WVpCcUJCcEtCSG8/view?usp=sharing I have tried different ways of implementing this but arrive at the same result - am I hitting a bug (I have Android 5.1.1) or is this a PEBCAK issue, lol. – avluis Sep 08 '15 at 03:37
  • Is your onFetched(..) getting called? Can you add a debug statement to see if it reaches there. I can't tell what could be the problem w/o looking at the code. – Nagesh Susarla Sep 08 '15 at 17:57
  • Yeah - I'll be debugging this today - thanks for the tip. – avluis Sep 09 '15 at 00:55
  • @avluis have you resolved your issue? if not, take a look at the xml file and remove the tint for the image. – Rain Man Sep 23 '15 at 02:38
  • @NageshSusarla please check this: http://stackoverflow.com/questions/34607919/not-getting-thumb-with-genres-universal-music-player – Sophie Jan 08 '16 at 07:55