Closed AndroidDeveloperLB closed 9 months ago
You can use glide custom target to receive webp frames and implement some code as WebpDrawable.java
@zjupure Not sure I understand how you mean is the best way to do it.
This is how I do it, but is it the best?
Glide.with(context.applicationContext).load(filePath).skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE)
.into(object : CustomTargetEx<Drawable>() {
...
override fun onResourceReady(drawable: Drawable, transition: Transition<in Drawable>?) {
when (drawable) {
is GifDrawable -> {
val bitmap =
Bitmap.createBitmap(drawable.intrinsicWidth, drawable.intrinsicHeight, Bitmap.Config.ARGB_8888)
val canvas = Canvas(bitmap)
drawable.setBounds(0, 0, bitmap.width, bitmap.height)
drawable.setLoopCount(GifDrawable.LOOP_FOREVER)
val callback = object : CallbackEx() {
override fun invalidateDrawable(who: Drawable) {
if (listener != null) {
who.draw(canvas)
handler.post {
listener?.onGotFrame(bitmap, drawable.frameIndex, drawable.frameCount)
}
}
}
}
drawable.callback = callback
drawable.start()
}
Similar to WebpDrawable.
It creates a new Bitmap this way on each frame and "rides on" the Drawable as it plays, so maybe it's not a good thing?
I want to play the animated GIF/WEBP in the background, and also get the callback of a bitmap being ready in a different thread of my choice (can be UI thread, can be a different one instead).
Is it possible?