【问题标题】:Trouble saving local video file to camera roll无法将本地视频文件保存到相机胶卷
【发布时间】:2014-09-29 16:06:06
【问题描述】:

在我的应用程序中,它会创建一个视频 (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];



         });
     }
     ];

【问题讨论】:

    标签: ios mpmovieplayercontroller mp4


    【解决方案1】:
    #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
                                    }];
    }
    

    【讨论】:

      猜你喜欢
      • 2013-07-22
      • 1970-01-01
      • 1970-01-01
      • 2016-05-01
      • 2015-01-06
      • 2014-02-02
      • 1970-01-01
      • 1970-01-01
      • 2015-05-12
      相关资源
      最近更新 更多