使歌曲图像非常慢(MediaMetadataRetriever) [英] Getting song image very slow (MediaMetadataRetriever)

查看:287
本文介绍了使歌曲图像非常慢(MediaMetadataRetriever)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用媒体播放器应用程序,正在使用 MediaMetadataRetriever 获取歌曲图像,并且正在获取图像,并且使用 Glide 进行设置,但是图像大约需要7到9秒的时间加载非常非常慢.我也尝试使用BitmapFactory,但同时也是.

I am working on media player application i am getting song image using MediaMetadataRetriever and i am getting image and and i set using Glide but image takes about 7-9 sec to load that is very very slow. i also try using BitmapFactory but that also same time.

所以有什么更快的方法可以获取歌曲图像.

so there is any faster way that can i get song image.

预先感谢

这是我使用MediaMetadataRetriever获取图像的代码.

Here is my code that i getting image using MediaMetadataRetriever.

MediaMetadataRetriever retriever = new MediaMetadataRetriever();
    retriever.setDataSource(songpath);
    byte[] art = retriever.getEmbeddedPicture();

    if (art != null) {

        Glide.with(c).load(art)
            .crossFade()
            .diskCacheStrategy(DiskCacheStrategy.SOURCE)
            .into(holder.songimage);

        //holder.songimage.setImageBitmap(BitmapFactory.decodeByteArray(art, 0, art.length));
    } else {
        Glide.with(c).load(R.drawable.splash)
                .crossFade()
                .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                .into(holder.songimage);

        //holder.songimage.setImageResource(R.drawable.splash);
    }

推荐答案

此方法返回ArrayList<CommonModel>.

public static ArrayList<CommonModel> getAllMusicPathList(Context context,String selectAll) {
        ArrayList<CommonModel> musicPathArrList = new ArrayList<>();
        Uri songUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;

        Cursor cursorAudio = context.getContentResolver().query(songUri, null, null, null, null);
        if (cursorAudio != null && cursorAudio.moveToFirst()) {

            Cursor cursorAlbum;
            if (cursorAudio != null && cursorAudio.moveToFirst()) {

                do {
                    Long albumId = Long.valueOf(cursorAudio.getString(cursorAudio.getColumnIndex(MediaStore.Audio.Media.ALBUM_ID)));
                    cursorAlbum = context.getContentResolver().query(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI,
                            new String[]{MediaStore.Audio.Albums._ID, MediaStore.Audio.Albums.ALBUM_ART},
                            MediaStore.Audio.Albums._ID + "=" + albumId, null, null);

                        if(cursorAlbum != null && cursorAlbum.moveToFirst()){
                            String albumCoverPath = cursorAlbum.getString(cursorAlbum.getColumnIndex(MediaStore.Audio.Albums.ALBUM_ART));
                            String data = cursorAudio.getString(cursorAudio.getColumnIndex(MediaStore.Audio.Media.DATA));

                            if("selectAll".equals(selectAll))
                            {
                                musicPathArrList.add(new CommonModel(data,albumCoverPath, true));
                            }
                            else
                            {
                                musicPathArrList.add(new CommonModel(data,albumCoverPath, false));
                            }
                        }

                } while (cursorAudio.moveToNext());
            }
        }
        return musicPathArrList;
    }

希望对您有帮助.

这篇关于使歌曲图像非常慢(MediaMetadataRetriever)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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