无法将保存的.mov文件移动到照片卷

时间:2014-04-01 09:40:39

标签: ios objective-c unity3d

我有一个图书馆,可以录制视频并将其保存到iPad。保存后我想把它移到照片库中,但我不能让它工作。

 BOOL success = [videoWriter finishWriting];
        if (!success) {
            NSLog(@"finishWriting returned NO");
        }

    [self cleanupWriter];

    id delegateObj = self.delegate;
    NSString *outputPath = [[NSString alloc] initWithFormat:@"%@/%@", [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0], @"output.mov"];
    NSURL *outputURL = [[NSURL alloc] initFileURLWithPath:outputPath];

    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
    if([library videoAtPathIsCompatibleWithSavedPhotosAlbum:outputURL]){
    [library writeVideoAtPathToSavedPhotosAlbum:outputURL completionBlock:^(NSURL *assetURL, NSError *error){
        if(error){
            NSLog(@"Failed to save movie");
        }
        else{
            NSLog(@"Saved movie");
        }
    }];
    }
    else{
        if(UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(outputPath)){
            UISaveVideoAtPathToSavedPhotosAlbum(outputPath, nil, nil, nil);
        }
        else{
            NSLog(@"Didn't save movie");
        }
    }

这将始终返回没有保存电影。这表示视频与滚动不兼容。问题是,我看不出它有什么问题,因为直到它出现在滚动中我才能看到视频,因为我在iOS上运行它。

我已经坚持了一段时间,我希望有人可以给我一些指示。

1 个答案:

答案 0 :(得分:0)

试试这段代码 -

NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];

    if (CFStringCompare((__bridge CFStringRef) mediaType, kUTTypeMovie, 0) == kCFCompareEqualTo)
    {
        NSString *moviePath = [[info objectForKey: UIImagePickerControllerMediaURL] path];

        if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath))
        {
            UISaveVideoAtPathToSavedPhotosAlbum (moviePath, nil, nil, nil);
        }
    }