RemoteControlClient とやり取りする音楽プレーヤー アプリがあります。ロック画面のウィジェットに表示するには、アルバム カバーの画像を読み込む必要があります。これを実現するためにピカソを使用しようとしています。私は次のコードを書きました:
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:
ロードされたビットマップ参照をサービスに保存しようとしましたが、役に立ちませんでした。
私のコードの何が問題なのか誰にもわかりませんか?
前もって感謝します。