Android-從音頻文件中獲取專輯圖片

如何獲取本地音頻文件的專輯圖片呢?不多說了,直接上代碼吧:

public static Bitmap setArtwork(Context context, String url, ImageView ivPic) {
        Uri selectedAudio = Uri.parse(url);
        MediaMetadataRetriever myRetriever = new MediaMetadataRetriever();
        myRetriever.setDataSource(context, selectedAudio); // the URI of audio file
        byte[] artwork;

        artwork = myRetriever.getEmbeddedPicture();

        if (artwork != null) {
            Bitmap bMap = BitmapFactory.decodeByteArray(artwork, 0, artwork.length);
            ivPic.setImageBitmap(bMap);

            return bMap;
        } else {
            ivPic.setImageResource(R.drawable.defult_music);
            return BitmapFactory.decodeResource(context.getResources(), R.drawable.defult_music);
        }
    }

其中url是從本地查詢的音頻文件信息中得到。如何得到音頻信息,google,baidu一大把哈。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章