Trying to play animated GIFs on Android here (see Android: How do a display a large animated gif given a url?). It\'s anything but smooth. On Android 1.5, the Movie.decodeSt
EDIT: I've migrated my project to Google GifFileDecoder, slightly patched. The MovieView class from the legacy solution remained mostly intact, but the GIF parsing logic is in Java.
Couple points of interest:
GifFileDecoder
does its own looping. If the animation is looped and you do readFrame()
until there are no more frames, this loop will be infinite; the decoder has its own wrap-around logic. Also, the buffer that readFrame()
returns is being reused over and over, so don't store the result of readFrame as it is, next time you call readFrame it will be overwritten. Make a deep copy instead. Also, the decoder assumes reading from a file, but can be trivially modified to read from any other stream, sacrificing the looping logic.
giflib 4.1.4 and NDK. You have to manually resolve the palette colors in the GIF to match one of Android's ARGBxxxx formats, then pass the pixel array to a Bitmap
object via copyPixelsFromBuffer()
. If you want transparency and/or animation, you have to go through extension blocks and look for the one with code 0xf9.
Shared my code, along with guidance, here: http://rathertech.blogspot.com/2014/04/splitting-gif-into-frames-on-android.html