3

我将视频保存到 photolibrary。它适用于以前的 ios,在 ios 7 videoAtPathIsCompatibleWithSavedPhotosAlbum 中,此行始终为 false

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

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

4

1 回答 1

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);
}
于 2014-04-22T06:59:12.210 回答