gpt4 book ai didi

android - "Cannot draw recycled bitmaps" picasso 异常

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:00:25 25 4
gpt4 key购买 nike

我有一个与 RemoteControlClient 交互的音乐播放器应用程序。我需要加载专辑封面图像以在锁屏小部件中显示它。我尝试使用 Piccasso 来实现这一点。我写了以下代码:

private final Target artworkTarget = new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom loadedFrom) {
remoteControlClient.editMetadata(false).putBitmap(RemoteControlClientCompat.MetadataEditorCompat.METADATA_KEY_ARTWORK,
bitmap).apply();
}

@Override
public void onBitmapFailed(Drawable drawable) {
Log.e(Constants.LOG_TAG, "Artwork loading failed");
}

@Override
public void onPrepareLoad(Drawable drawable) {
}
};

...

private void playNextSong(int songPosition) {
...

String artworkUrl = Constants.Urls.BASE_ARTWORK_URL + currentSong.getArtworkId();
Picasso.with(this).load(artworkUrl).skipMemoryCache().into(artworkTarget);
// Update the remote controls
remoteControlClient.editMetadata(true)
.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, currentSong.getArtist().getName())
.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, currentSong.getAlbum().getName())
.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, currentSong.getName())
.apply();

...
}

但有时我会遇到异常:

    ERROR/AndroidRuntime(31121): FATAL EXCEPTION: main
java.lang.IllegalArgumentException: Cannot draw recycled bitmaps
at android.view.GLES20Canvas.drawBitmap(GLES20Canvas.java:772)
at android.view.GLES20RecordingCanvas.drawBitmap(GLES20RecordingCanvas.java:105)
at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:440)
at com.squareup.picasso.PicassoDrawable.draw(PicassoDrawable.java:96)
at android.widget.ImageView.onDraw(ImageView.java:1025)
at android.view.View.draw(View.java:13944)
at android.view.View.getDisplayList(View.java:12838)
at android.view.View.getDisplayList(View.java:12880)
at android.view.View.draw(View.java:13657)
at android.view.ViewGroup.drawChild(ViewGroup.java:3083)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2920)
at android.view.View.getDisplayList(View.java:12833)
at android.view.View.getDisplayList(View.java:12880)
at android.view.View.draw(View.java:13657)
at android.view.ViewGroup.drawChild(ViewGroup.java:3083)
at android.widget.ListView.drawChild(ListView.java:3331)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2920)
at android.widget.AbsListView.dispatchDraw(AbsListView.java:2357)
at android.widget.ListView.dispatchDraw(ListView.java:3326)
at android.view.View.draw(View.java:13947)
at android.widget.AbsListView.draw(AbsListView.java:3693)
at android.view.View.getDisplayList(View.java:12838)
at android.view.View.getDisplayList(View.java:12880)
at android.view.View.draw(View.java:13657)
at android.view.ViewGroup.drawChild(ViewGroup.java:3083)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2920)
at android.view.View.getDisplayList(View.java:12833)
at android.view.View.getDisplayList(View.java:12880)
at android.view.View.draw(View.java:13657)
at android.view.ViewGroup.drawChild(ViewGroup.java:3083)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2920)
at android.view.View.getDisplayList(View.java:12833)
at android.view.View.getDisplayList(View.java:12880)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3057)
at android.view.View.getDisplayList(View.java:12775)
at android.view.View.getDisplayList(View.java:12880)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3057)
at android.view.View.getDisplayList(View.java:12775)
at android.view.View.getDisplayList(View.java:12880)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3057)
at android.view.View.getDisplayList(View.java:12775)
at android.view.View.getDisplayList(View.java:12880)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3057)
at android.view.View.getDisplayList(View.java:12775)
at android.view.View.getDisplayList(View.java:12880)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3057)
at android.view.View.getDisplayList(View.java:12775)
at android.view.View.getDisplayList(View.java:12880)
at android.view.HardwareRenderer$GlRenderer.buildDisplayList(HardwareRenderer.java:1411)
at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:1359)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:2367)
at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2239)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1872)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
at android.view.Choreographer.doCallbacks(Choreographer.java:562)
at android.view.Choreographer.doFrame(Choreographer.java:532)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:

我试图在我的服务中保存加载的位图引用,但没有帮助。
有人知道我的代码有什么问题吗?
提前致谢。

最佳答案

我猜您使用的是 Android 4.3 或更高版本的设备。 4.3 的 RemoteControlClient 实现在特定条件下对艺术品进行回收。见

http://androidxref.com/4.3_r2.1/xref/frameworks/base/media/java/android/media/RemoteControlClient.java#556

如果 Build.VERSION.SDK_INT >= 18,您基本上必须复制位图。

关于android - "Cannot draw recycled bitmaps" picasso 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19345576/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com