0
我正在开发音乐播放器,并使用音频文件中的图片将其显示在我的应用的用户界面中,如果我非常快速地更改音乐(上一个,下一个按钮),那么我可以得到java.lang.RuntimeException: Canvas: trying to use a recycled bitmap
,但是如果我非常快地改变音乐,Play市场上的流行玩家就不会遇到这个问题。我怎样才能避免这个错误,以及在其他音乐应用程序?EmbeddedPicture&java.lang.RuntimeException:Canvas:试图使用回收的位图
具有相同的错误类似的问题没有帮助我
MediaService类
MediaMetadataRetriever mMetaRetriever = new MediaMetadataRetriever();
mMetaRetriever.setDataSource(songPath);
byte[] art = mMetaRetriever.getEmbeddedPicture();
Bitmap iconUrl = null;
try {
if (art != null) {
iconUrl = BitmapFactory.decodeByteArray(art, 0, art.length);
}
} catch (Exception e) {
}
UI类
try {
// with or without it error happens anyway
/*if (mBitmap != null && !mBitmap.isRecycled()) {
mBitmap.recycle();
mBitmap = null;
mLogo.setImageBitmap(null);
}*/
mBitmap = metadata.getBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART);
mLogo.setImageBitmap(mBitmap);
} catch (Exception e) {
}
你已经把两个代码示例。你在使用哪一个?每个代码示例面临的错误是什么? – Dibzmania