Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIVideoAtPathIsCompatibleWithSavedPhotosAlbum returns false when deploying on the iPhone

One of my app's features is to download a mp4 file and store it to the local phone album.

I have tried several approaches since and the result is always the same, it worked on the simulator but not on the actual iPhone. Xcode is version 5.0.1, iPhone 4.

Below is the code I applied on the last attempt before posted here using ASIHttpRequest library and the result is still the same, it worked on the simulator but not the phone itself.

  1. download:

    ASIHTTPRequest* request = [ASIHTTPRequest requestWithURL:url]; // url is the address to the mp4 file
    
    NSString* filePath = [NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), filename]; //filename is the file I save to, e.g. xxx.mp4
    
    [request setDownloadDestinationPath:filePath];
    [request setDelegate:self];
    [request setDidFinishSelector:@selector[ASIRequestDone:)];
    [request setDidFailSelector:@select[ASIRequestFail:)];
    
  2. when download is finished, save it to the photo album (in ASIRequestDone delegate)

    if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(filePath))
    {
        //comes to here when running in simulators
        UISaveVideoAtPathToSavedPhotosAlbum(filePath, self, @selector(video:didFinishSavingWithError:cotextInfo:),nil);
    } 
    else 
    {
        //always comes to here when running on the actual iPhone.
    }
    

I have checked the pathFile it's this

/private/var/mobile/Applications/xxxxxxxxxx/tmp/xxxxx.mp4

which is alright to me. What I am not getting is it works fine when running on Simulator and hence I am stuck not sure what to do next. (I have also checked the permission accessing the the photo albums and yes the app has it).

I also tried to removed the compatible checking and went straight into the method UISaveVideoAtPathToSavedPhotosAlbum, it didn't throw any error on delegate didFinishSavingWithError. however, the video didn't show up on the photo album either, I am guessing it's correct as the phone seems to say that video is not compatible to be shown on the album. Again, my issue is that it does work on the simulator and how do I fix this on the actual iphone, e.g. why it thinks the video is not compatible? is something to do with the mp4 itself or is it something to do during the download step? What could I do next to resolve the issue? (ps. I also have control over the mp4 files, is there a list of mp4 compatibility on the iphone that you know? I am thinking perhaps it's genuine that the file is not compatible on the phone (but on the simulator!?))

like image 900
user3385033 Avatar asked Mar 05 '14 19:03

user3385033


Video Answer


1 Answers

Found the answer to my question and I hope it could help out someone who suffers from the same issue. Turns out video resolution is the factor between the simulator and the actual phone when it comes to store video to the gallery; to be specific:

Compatibility checking UIVideoAtPathIsCompatibleWithSavedPhotosAlbum would FAIL on the actual phone but would PASS on the simulator given a sample clip capturrd as 1080p. I came cross this link a week after my post with luck.

"What video formats are compatible with the assets library?"

And I did the experiment similar to that by capturing 720p video clips instead and all files were able to be saved to the gallery. Weird thing is that the actual iphone can play the HLS stream at 1080p; howeve it won't store clips unless they are 720p, not to me anyway. And the misleading bit is that the simulator can actually do 1080p.

like image 184
user3385033 Avatar answered Nov 09 '22 14:11

user3385033