无法将本地视频文件保存到相机胶卷

时间:2014-09-29 16:06:07

标签: ios mpmovieplayercontroller mp4

在我的应用程序中,它会创建一个视频(MP4)并在MPMoviePlayer中播放它,现在我想将视频保存到相机胶卷。如何将该视频保存到相机胶卷?

outputFilePath是存储视频文件的位置。

 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];



         });
     }
     ];

1 个答案:

答案 0 :(得分:0)

#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
                                }];
}