ios 7视频保存问题

时间:2013-09-11 08:30:03

标签: iphone xcode video ios7

我将视频保存到photolibrary.Its适用于以前的ios,在ios 7中 videoAtPathIsCompatibleWithSavedPhotosAlbum此行总是假的

这是我的代码,任何人都可以帮助我。

NSString *myPathDocs =  [documentsDirectory stringByAppendingPathComponent:@"NewmergeVideo.mov"];

BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:myPathDocs];
if (fileExists) {
    [[NSFileManager defaultManager] removeItemAtPath: myPathDocs error:NULL];

}

NSURL *url = [NSURL fileURLWithPath:myPathDocs];
NSLog(@"%@",url);
AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:mixComposition presetName:AVAssetExportPresetHighestQuality];
exporter.outputURL=url;
//[exporter setVideoComposition:MainCompositionInst];
exporter.outputFileType = AVFileTypeQuickTimeMovie;

[exporter exportAsynchronouslyWithCompletionHandler:^
 {
     dispatch_async(dispatch_get_main_queue(), ^{
         [self _exportDidFinish:exporter];

     });
 }];

这里是保存代码

- (void)_exportDidFinish:(AVAssetExportSession*)session
{ 
    NSURL *outputURL = session.outputURL;
    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];

    NSLog(@"%@",outputURL);

    if ([library videoAtPathIsCompatibleWithSavedPhotosAlbum:outputURL]) {
        [library writeVideoAtPathToSavedPhotosAlbum:outputURL
                                    completionBlock:^(NSURL *assetURL, NSError *error){
                                        dispatch_async(dispatch_get_main_queue(), ^{
                                            if (error) {
                                                NSLog(@"writeVideoToAssestsLibrary failed: %@", error);

                                            }else{
                                                NSLog(@"Writing3");

                                            }

                                        });

                                    }];
    }
    [library release];
}

在之前的ios nsurl中 文件://localhost/var/mobile/Applications/99B72CBA-A426-4F04-B7B2-2B61F0B0C513/Documents/NewmergeVideo.mov

在ios 7 nsurl中 文件:///var/mobile/Applications/791244EE-771B-46C9-BD57-BA0BE6CACD3C/Documents/NewmergeVideo.mov

1 个答案:

答案 0 :(得分:0)

您可以使用此代码保存文件。(它正常工作)

 if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(outputURL))
{
      UISaveVideoAtPathToSavedPhotosAlbum(outputURL, self, @selector(video:didFinishSavingWithError:contextInfo:), nil);
}

-(void) video: (NSString *) videoPath didFinishSavingWithError: (NSError *) error contextInfo: (void *) contextInfo
{
    if(error)
        NSLog(@"Finished saving video with error: %@", error);
}