coil-kt / coil

Image loading for Android and Compose Multiplatform.
https://coil-kt.github.io/coil/
Apache License 2.0
10.65k stars 649 forks source link

Set Loop Count on GIF #127

Closed mattinger closed 4 years ago

mattinger commented 4 years ago

I don't currently see any way to set the loop count on a .gif file. There are times when we get gif files that have an indefinite loop coded in, but would like to play it only once. It would be great if we could maybe be another ImageView extension function which takes a loop count parameter, which can be passed off to MovieDrawable to determine how many times to loop the movie.

In addition, it would also be nice to know when a particular gif loops via some sort of callback interface/lambda.

It's possible this might required using AnimatedImageDrawable, but that's only API 28 or higher.

colinrtwhite commented 4 years ago

Great idea! Definitely open to a PR that adds this to MovieDrawable. This is already supported in AnimatedImageDrawable via setRepeatCount.

mattinger commented 4 years ago

The issue is libraries like glide (what we're migrating from) have a magic loop count available LOOP_INTRINSIC that indicates it should get it's loop count from the metadata in the actual image file. I think it would be easy enough to do a fixed loop count, and an infinite loop (which is what MovieDrawable does right now). The problem is figuring out the intrinsic (built in) loop count for the animated gif. Movie does not support anything like this.

mattinger commented 4 years ago

Also, as a side note, my app crashes every time if i try to use ImageDecoderDecoder. I haven't been able to get a useful stack track yet though.

colinrtwhite commented 4 years ago

@mattinger The ImageDecoderDecoder crash is due to this framework issue. I've worked around it in 0.8.0-SNAPSHOT, though it might still be worth using GifDecoder exclusively.

mattinger commented 4 years ago

@colinrtwhite I see the change to MovieDrawable. Is there going to be a corresponding change to the load function to allow us to actually set the repeat count when the movie is inflated? That still seems to be missing. I imagine something in the Decoder.Options would be appropriate.

mattinger commented 4 years ago

I can submit a PR, but it should be a relatively small change. I'd think adding it to request builder and sending it down the chain to the Options class would be the best approach. I'd have to go through some approvals at work since i've never submitted to this project before. I can get the ball rolling though.

colinrtwhite commented 4 years ago

@mattinger Good point, I added an extension to set the repeat count as part of the request here.

mattinger commented 4 years ago

@colinrtwhite Any idea when you plan on a non snapshot release?

colinrtwhite commented 4 years ago

@mattinger Likely within the next 1-2 weeks.