从Android的MP3文件中提取专辑封面封面、文件、专辑、Android

2023-09-04 08:03:43 作者:孤独的寂寞

大家好,         在我的媒体播放器,我需要显示专辑封面(我不知道它是如何发音actually..I希望右)的歌曲。我知道了,我要提取从歌曲本身,而是如何的形象呢?中号不知道。所以任何帮助,如果可能的话有一些种类的code。谢谢。

Hello Everyone , In my media player i need to display the album cover(i dont know how it pronounced actually..I hope right) of the song. I knew for that i have to extract the image from the song itself but how? m wondering. So any help, if possible with some sorts of code. Thanks.

推荐答案

有关API 10及以上

for api 10 and above

android.media.MediaMetadataRetriever mmr = new MediaMetadataRetriever();
        mmr.setDataSource(songsList.get(songIndex).get("songPath"));

        byte [] data = mmr.getEmbeddedPicture();
               //coverart is an Imageview object

        // convert the byte array to a bitmap
        if(data != null)
        {
            Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
            coverart.setImageBitmap(bitmap); //associated cover art in bitmap
            coverart.setAdjustViewBounds(true);
            coverart.setLayoutParams(new LinearLayout.LayoutParams(500, 500));
        }
        else
        {
            coverart.setImageResource(R.drawable.fallback_cover); //any default cover resourse folder
            coverart.setAdjustViewBounds(true);
            coverart.setLayoutParams(new LinearLayout.LayoutParams(500,500 ));
        }