penfeizhou / APNG4Android

Android animation support for APNG & Animated WebP & Gif & Animated AVIF, High performance
Apache License 2.0
570 stars 75 forks source link

Too fast Animation of APNG loaded via Glide into RecyclerView #176

Closed Zylence closed 2 months ago

Zylence commented 1 year ago

Issue Info

Info Value
Device Info Poco F3 and Moto G5
System Version 12 and 8.1
APNG4Android Library Version 2.24.0
Repro rate 100%
Repro with our demo project not checked
Demo project link BugDemo.zip

Issue Description and Steps

Too fast Animation of APNG inside RecyclerView loaded via Glide

Sometimes when loading a bunch of APNGs into a RecyclerView some of them are speed up by roughly 2x. This happens inside the example app ~1/20 of the time when loading 10 initial images. 

Slowly adding them exhibits the same behavior, but is much more frequently reproducible. When APNGs are loaded via button click, they animate faster until automatic scrolling kicks in.

Scrolling or refreshing in general seems to reset them to "normal" speeds. 

I attached some recorded videos as well to showcase it.

Note:

https://user-images.githubusercontent.com/81491426/214593147-d2445b5b-b871-4502-908a-370d5ed29bd2.mp4 https://user-images.githubusercontent.com/81491426/214593156-e810a1ca-9e8e-4670-805e-716b24ece496.mp4

charlag commented 6 months ago

We can reproduce it every time without RecyclerView.

Image in question: https://mastodon.derg.nz/system/custom_emojis/images/000/000/208/original/1ba4096c050a3b1b.png

Code in question: https://github.com/tuskyapp/Tusky/blob/69946934968fd86b50962899acbba2fe0b1eb309/app/src/main/java/com/keylesspalace/tusky/util/CustomEmojiHelper.kt#L57-L66

https://github.com/tuskyapp/Tusky/blob/69946934968fd86b50962899acbba2fe0b1eb309/app/src/main/java/com/keylesspalace/tusky/util/CustomEmojiHelper.kt#L136-L163

Please let us know if we can help with debugging it somehow

charlag commented 6 months ago

It also reproduces in isolation with empty activity like this:

class TestActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        val layout = FrameLayout(this)

        val imageView = ImageView(this)
        imageView.layoutParams = LinearLayout.LayoutParams(Utils.dpToPx(this, 64), Utils.dpToPx(this, 64))
        layout.addView(imageView)
        setContentView(layout)

        Glide.with(this)
            .load("https://mastodon.derg.nz/system/custom_emojis/images/000/000/208/original/1ba4096c050a3b1b.png")
            .into(imageView)
    }
}

so it has nothing to do with RecyclerView in or custom targets in our case

tudou0digua commented 6 months ago

It also reproduces in isolation with empty activity like this:

class TestActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        val layout = FrameLayout(this)

        val imageView = ImageView(this)
        imageView.layoutParams = LinearLayout.LayoutParams(Utils.dpToPx(this, 64), Utils.dpToPx(this, 64))
        layout.addView(imageView)
        setContentView(layout)

        Glide.with(this)
            .load("https://mastodon.derg.nz/system/custom_emojis/images/000/000/208/original/1ba4096c050a3b1b.png")
            .into(imageView)
    }
}

so it has nothing to do with RecyclerView in or custom targets in our case

the reason of the problem of this image url (https://mastodon.derg.nz/system/custom_emojis/images/000/000/208/original/1ba4096c050a3b1b.png) is: this image frameDuration is 10ms,when browser decode image , force set frame duration to 100ms but this library just use 10ms (as the image required)

tudou0digua commented 6 months ago

Issue Info

Info Value
Device Info Poco F3 and Moto G5 System Version 12 and 8.1
APNG4Android Library Version 2.24.0
Repro rate 100%
Repro with our demo project not checked Demo project link BugDemo.zip

Issue Description and Steps

Too fast Animation of APNG inside RecyclerView loaded via Glide

Sometimes when loading a bunch of APNGs into a RecyclerView some of them are speed up by roughly 2x. This happens inside the example app ~1/20 of the time when loading 10 initial images. 

Slowly adding them exhibits the same behavior, but is much more frequently reproducible. When APNGs are loaded via button click, they animate faster until automatic scrolling kicks in.

Scrolling or refreshing in general seems to reset them to "normal" speeds. 

I attached some recorded videos as well to showcase it.

Note:

  • It may also happen that some only speed up after being scrolled into view -  but that's rare
  • I have also seen this behavior without glide - but that was not reproducible

https://user-images.githubusercontent.com/81491426/214593147-d2445b5b-b871-4502-908a-370d5ed29bd2.mp4 https://user-images.githubusercontent.com/81491426/214593156-e810a1ca-9e8e-4670-805e-716b24ece496.mp4

@penfeizhou use the demo code, in mi 11(Android 13), can reproduce the bug

this is temp fix

214