开发者

Save MP4 into iPhone photo album

I have an app that plays video clips through the MPMovieplayer. These clips are in mp4 format and everything works dandy. I want to take that same clip and save it into the photo album. This works if I manually sync the video from a computer through iTunes to the phone. It appears to transcode the video file and store it as a .MOV format.

However, when I try and save the video while in the app via code, I get a video format error. So my question is how do I get my video to save in the photo album? If this is not possible with mp4 how do I transcode (in app) to .MOV?

Here is the code:

ALAssetsLibrary* library = [[ALAssetsLibrary alloc]init];

    if ([library videoAtPathIsCompatibleWithSavedPhotosAlbum:moviePlayerController.con开发者_如何学JAVAtentURL])
    {

        NSURL *clipURl = moviePlayerController.contentURL;
        [library writeVideoAtPathToSavedPhotosAlbum:clipURl completionBlock:^(NSURL *assetURL, NSError *error) 
         {
             if (error)
                 [ErrorAlertView showError:error];
             else [ErrorAlertView showErrorTitle:@"Success" message:@"Your video clip is saved"];
         }];
    }
    [library release];


Is your contentURL a file path URL or a web URL? For the writeVideoAtPathToSavedPhotosAlbum method, in my testing you actually need a file path URL created (for example) in this way:

NSString *pathString = [[NSBundle mainBundle] pathForResource:@"filename" ofType:@"mp4"];
NSString *pathURL = [NSURL fileURLWithPath:pathString isDirectory:NO];

This means you need to first download the movie from the web, if you're using a web URL. I recommend ASIHTTPRequest, using the setDownloadDestinationPath: method to set the download directory.

In general, mp4 files should work if they're the right resolution for the right (retina, non-retina, iPad) device (see my tests of supported video files here).

If the video still gives a NO response on videoAtPathIsCompatibleWithSavedPhotosAlbum: after making absolutely sure the file path URL is correct, then you'll need to use AVAssetExportSession (with AVAssetExportPresetLowQuality, AVAssetExportPresetMediumQuality, or AVAssetExportPresetHighestQuality) to get a device-appropriate file that you can then save to the Photo Album.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜