Android通用音乐播放器在MediaItemViewHolder中添加专辑封面 [英] Android universal music player add album cover in the MediaItemViewHolder

查看:337
本文介绍了Android通用音乐播放器在MediaItemViewHolder中添加专辑封面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不确定这里有多少人熟悉



屏幕截图#2 :用户点击该项目后播放歌曲





我不是真的确定导致专辑最初为空的原因。查看 AlbumArtCache.java 我看不到任何可能导致此问题的OnClickListener限制。



如何解决此问题?

解决方案

cache.getIconImage(url)实际上并没有获取url并将其存储在缓存中。它返回当前值或null。相反,你必须调用 AlbumArtCache #fetch(String url,FetchListener listener)



这是一个很好的原型 FullScreenPlayerActivity #fetchImageAsync(MediaDescription description)



以下是在项目可播放时您可以在方法中执行的操作。

  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);
}


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:

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

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?

解决方案

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);
}

这篇关于Android通用音乐播放器在MediaItemViewHolder中添加专辑封面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆