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.
Looks like you may have to do some digging into the Photos or Asset Library frameworks -- see here http://stackoverflow.com/a/5187841/3943258.
- 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+):
- Use
+[PHAsset fetchAssetsWithALAssetURLs:options:]
to retrieve aPHAsset
using asset URL (available under UIImagePickerControllerReferenceURL) - 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.