Flipboard/FLAnimatedImage

Can't play local gif

Closed this issue · 5 comments

Hello,

I'm trying to play gif file from my local storage (the camera roll for example) but without success. Here is my code:

myFLAnimatedImageView.animatedImage = FLAnimatedImage(animatedGIFData: localImage.asData())
  • The localImage is a UIImage I got from a UIImagePickerController

Am I doing something wrong?

not sure what your asData() method does, but if it is a UIImage, it isn't going to be an animated GIF. You'll probably want a different API (Photos.framework) to fetch the GIF from the user's library.

I'm using the standard UIImagePickerController class to pick the user media. I'm getting the UIImage and the NSURL. I also tried to do NSData(gifNSURL) but without success.

I'm trying to understand what you mean. Do you mean that I need to allow the user to pick images with UIImagePickerController and to pick gifs with another control?

Hmm, that's odd. I would expect using the returned NSURL to work. I just tried this though and I'm getting the same thing.

screen shot 2016-01-04 at 5 09 05 pm

Looks like you may have to do some digging into the Photos or Asset Library frameworks -- see here http://stackoverflow.com/a/5187841/3943258.

kean commented
  • UIImage (both UIImagePickerControllerEditedImage and UIImagePickerControllerOriginalImage) from UIImagePickerController is a representation of an image that only has a single frame. You need a full original image data to display an asset as an animated image.
  • NSURLConnection/NSURLSession/NSData and other similar APIs don't support assets-library:// scheme.

How to get image data using Photos Kit (iOS 8+):

  1. Use +[PHAsset fetchAssetsWithALAssetURLs:options:] to retrieve a PHAsset using asset URL (available under UIImagePickerControllerReferenceURL)
  2. Use -[PHImageManager requestImageDataForAsset:options:resultHandler:] method to get full original image data and then display it using FLAnimatedImage.

You can do the similar thing using Assets Library but it is deprecated and I won't recommend using it unless you absolutely must support iOS 7 and lower.

Sounds like this is resolved, thanks @kean 😉