如何獲取本地音頻文件的專輯圖片呢?不多說了,直接上代碼吧:
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一大把哈。