简体   繁体   中英

Cant move saved .mov file to the photo roll

I have a library which records a video and saves it to the iPad. After it is saved I want to move it into the photo library but I cannot get this to work.

 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");
        }
    }

This will always return Didn't save movie. This indicates the video is not compatible to be put in the roll. The thing is, I can't see whats wrong with it, because I cannot look at the video until it appears in the roll, since I'm running this on iOS.

I've been stuck on this for a while and I hope someone can give me some pointers.

try this code -

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);
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM