Getting song image very slow (MediaMetadataRetriev

2019-08-07 06:08发布

问题:

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.

Thanks in advance

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

回答1:

This method returns 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;
    }

I hope this helps you.