如何获得的缩略从音频网址在安卓使用滑翔

0

的问题

试图载的音频缩略从网址下滑,但是没工作

Glide
                .with(this)
                .load("http://api.boleiachain.com/upload/musictest.mp3")
                .apply(options)
                .centerCrop()
                .placeholder(R.drawable.ic_loading)
                .into(civ_image);

我已经尝试过这种

public  Bitmap coverpicture(String path) {

        Bitmap bitmap=null;
        MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
        mediaMetadataRetriever.setDataSource(path, new HashMap<String, String>());
        try {
            final byte[] coverImage = mediaMetadataRetriever.getEmbeddedPicture();
             bitmap= BitmapFactory.decodeByteArray(coverImage, 0, coverImage.length);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return bitmap;

    }

Glide
                .with(this)
                .load(coverpicture("http://api.boleiachain.com/upload/musictest.mp3"))
                .apply(options)
                .centerCrop()
                .placeholder(R.drawable.ic_loading)
                .into(civ_image);

它的工作原理,但有延误,这是不好的实践在它不会适配器

android audio url
2021-11-23 03:44:23
1

最好的答案

1

你可以缓位图和检查高速缓冲存在之前的呼叫coverPicture方法

  ....load(getCoverpicture("http://api.boleiachain.com/upload/musictest.mp3"))



HashMap<String,Bitmap> cache = new HashMap<String,Bitmap>();
public  Bitmap getCoverpicture(String path) {
    if(cache.containsKey(path)){ return cache.get(path);
    }else{
        Bitmap bitmap = coverpicture(path);
        cache.put(path,bitmap);
        return bitmap;
    }
}

它有一些语法错误

2021-11-26 11:34:53

其他语言

此页面有其他语言版本

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................