1

I am having issues with UISaveVideoAtPathToSavedPhotosAlbum. I am running a social media site that allows users to post videos and other users are able to save the videos to their Photos Album by clicking a button. Here is my code:

if (buttonIndex == 0)
{
    NSString *movieURL = self.postInfo.referenceText;
    if (self.postInfo.type == SBPostTypeVideo)
    {
        if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(movieURL)){
        UISaveVideoAtPathToSavedPhotosAlbum(movieURL, nil, nil, nil);
        }
    }
}

This code fails, however, with the following output:

 Video http://VIDEOURL.COM/14.mov cannot be saved to the saved photos album: Error Domain=NSOSStatusErrorDomain Code=2 "This movie could not be played." UserInfo=0x9c2a400 {NSLocalizedDescription=This movie could not be played.}

The link is the correct path to the video. I believe the issue may be because it is attempting to save the original video URL to the camera, which is too big of a file size, though I am not positive. Any help either compressing it for download or anything else to get this to work would be much appreciated. Thanks so much!

rmaddy
  • 314,917
  • 42
  • 532
  • 579
user2287517
  • 57
  • 2
  • 9

2 Answers2

1

UISaveVideoAtPathToSavedPhotosAlbum only works to save files into the library. If you want to save a video from the web, you need to download the video file, save it to disk, get the file URL of that file on disk and then save using the file URL.

UIVideoAtPathIsCompatibleWithSavedPhotosAlbum checks the validity of the video file, basically by checking it can play the video file. Again, this is by file URL. I don't think there is a size limit other than available disk space.

Wain
  • 118,658
  • 15
  • 128
  • 151
0

In my case it happened just after composing a video using other videos downloaded from the web. While testing on iPhone5 is was all good, but on iPhone4 it never worked, until I realized that the video I composed have a higher resolution than iPhone4 player could play, so it denied access to record the final video to Camera Roll.

So, if you want to save a downloaded video straight to the Camera Roll, you might need to check if the resolution fits the one supported by the device. As I was using AVAssetExportSession the way out was to set the quality of the video being generated as follows:

self.exportSession = [[AVAssetExportSession alloc] initWithAsset:composition presetName:AVAssetExportPresetMediumQuality];
self.exportSession.outputURL = [NSURL fileURLWithPath:path];
self.exportSession.outputFileType = AVFileTypeQuickTimeMovie;
[self.exportSession exportAsynchronouslyWithCompletionHandler:^{

    switch (self.exportSession.status)
    {
        case AVAssetExportSessionStatusCompleted:
            NSLog(@"Export OK");
            if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(path)) {
                UISaveVideoAtPathToSavedPhotosAlbum(path, self, @selector(video:didFinishSavingWithError:contextInfo:), nil);
            }
            break;
        case AVAssetExportSessionStatusFailed:
            NSLog (@"AVAssetExportSessionStatusFailed: %@", self.exportSession.error);
            break;
        case AVAssetExportSessionStatusCancelled:
            NSLog(@"Export Cancelled");
            break;
    }
}];

Hope it helps! ;)

Linox83
  • 3
  • 2