Giter Site home page Giter Site logo

Question: is it possible to decode the frames of GIF/WEBP and get callbacks for playing them in specific threads? about glidewebpdecoder HOT 2 CLOSED

AndroidDeveloperLB avatar AndroidDeveloperLB commented on July 2, 2024
Question: is it possible to decode the frames of GIF/WEBP and get callbacks for playing them in specific threads?

from glidewebpdecoder.

Comments (2)

zjupure avatar zjupure commented on July 2, 2024

You can use glide custom target to receive webp frames and implement some code as WebpDrawable.java

from glidewebpdecoder.

AndroidDeveloperLB avatar AndroidDeveloperLB commented on July 2, 2024

@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?

from glidewebpdecoder.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.