通用方法大家都会想到使用系统媒体库去获取专辑缩略图.
今天介绍另外一种方法,通过MediaMetadataRetriever对象获取,
获取方法代码如下:
/**
* 获取音频缩略图Bitmap
* @param path 音频路径
* @return
*/
public static Bitmap coverPicture(String path) {
//path=/mnt/media_rw/sdcard/Music/BINGBIAN.mp3
Bitmap bitmap = null;
try {
MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
// mediaMetadataRetriever.setDataSource(path, new HashMap<String, String>());
mediaMetadataRetriever.setDataSource(path);
final byte[] coverImage = mediaMetadataRetriever.getEmbeddedPicture();
if (coverImage != null) {
bitmap = BitmapFactory.decodeByteArray(coverImage, 0, coverImage.length);
}
ALog.d(TAG,"coverPicture path="+path+", bitmap="+bitmap);
} catch (Throwable e) {
e.printStackTrace();
}
return bitmap;
}