2014-09-29 98 views
0

在我的應用程序,它創建一個視頻(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]; 



     }); 
    } 
    ]; 

回答

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 
           }]; 
} 
相關問題