felipecsl/GifImageView

Support for non-looping gifs

Closed this issue · 6 comments

Support for non-looping gifs

This fixed is wrong!
You must put the following code:

if (animationCallback != null) {
animationCallback.onStop();
animationThread = null;
break;
}

inside the do...while loop on run method (at the end position) and remove all the code you added after the while.

It works for me.

Why is it wrong?

When the loop breaks, animation stops so onStop should be called there. Instead of putting that block before every break statement in that loop, you just put it outside and it will be called after break.

Your code is wrong because the do...while loop never exit so, the code outside that will never be executed!

Did you try your code? Did it work?

Yes.

It works because it sets "animating" to true or false depending on the loop count and the frame pointer. In the next iteration of the loop, the "animating" variable is checked three times and the loop breaks if it's false, after which the code will be called.

It's very strange: with my animated gif the loop never stops :(

I had to change the code as I told you... Can you send me a gif that works for you?
Thanks

It's dependent on the gif. Gifs have metadata to determine how many times they should loop. Now the only thing wrong in that code is that if you have loopCount != 0, then it loops forever instead of looping the correct number of times.

https://raw.githubusercontent.com/AfzalivE/GifImageView/74644c0e02761f93c707a626ca7b76dfc702dfcc/app/src/main/assets/chop.gif