In my app, it creates a video(MP4) and plays it in MPMoviePlayer and now i would like to save the video to the camera roll. How do I go about saving that video to camera roll?
The outputFilePath is where the video file is stored.
AVAssetExportSession* _assetExport = [[AVAssetExportSession alloc] initWithAsset:mixComposition presetName:AVAssetExportPresetHighestQuality];
_assetExport.outputFileType = @"public.mpeg-4";
_assetExport.outputURL = outputFileUrl;
[_assetExport exportAsynchronouslyWithCompletionHandler:
^(void ) {
dispatch_async(dispatch_get_main_queue(), ^{
[spinner stopAnimating];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:outputFilePath]];
[moviePlayer.view setFrame:CGRectMake(0, 100, 320, 320)];
[moviePlayer prepareToPlay];
[moviePlayer repeatMode];
moviePlayer.backgroundView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:moviePlayer.view];
[moviePlayer play];
});
}
];
#import <AssetsLibrary/AssetsLibrary.h>
- (void)saveMovieToCameraRoll
{
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library writeVideoAtPathToSavedPhotosAlbum:_movieURL
completionBlock:^(NSURL *assetURL, NSError *error) {
if (error)
NSLog(@"Error saving to camera roll: %@",error);
else
// remove temporary movie file
}];
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.