ALAssetsLibraryWriteVideoCompletionBlock returns undefined values

ALAssetsLibraryWriteVideoCompletionBlockreturns undefined values. If assetURL is nil, then the error should not be nil, that is, return me some description of the error.

See Apple's documentation here .

When I record a short video, ALAssetsLibraryWriteVideoCompletionBlockassetURL returns a good value, but when I record a long 3 or 4 GB video, returnURL returns return and nil. The video is recorded in the tmp file because I see this video in a temporary folder in my application. It seems that the IOS framework is trying to make a copy of this temporary file in the photo album, and the iPhone does not have enough memory to copy this temporary file into the photo album and return the path to this file (assetURL).

Is this a bug in iOS? If so, can this be fixed?

UPDATE: My files are less than 4 GB. Thanks

UPDATE with source code:

    -(void)recorder:(AVCamRecorder *)recorder recordingDidFinishToOutputFileURL:(NSURL *)outputFileURL error:(NSError *)error
    {    
    if ([[self recorder] recordsAudio] && ![[self recorder] recordsVideo]) {
    // If the file was created on a device that doesn't support video recording, it can't be saved to the assets 
    // library. Instead, save it in the app Documents directory, whence it can be copied from the device via
    // iTunes file sharing.
    [self copyFileToDocuments:outputFileURL];

    if ([[UIDevice currentDevice] isMultitaskingSupported]) {
        [[UIApplication sharedApplication] endBackgroundTask:[self backgroundRecordingID]];
    }       

    if ([[self delegate] respondsToSelector:@selector(captureManagerRecordingFinished:)]) {
        [[self delegate] captureManagerRecordingFinished:self];
    }
}
else {  
    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
    [library writeVideoAtPathToSavedPhotosAlbum:outputFileURL
                                completionBlock:^(NSURL *assetURL, NSError *error) {
                                    if (error) {
                                        if ([[self delegate] respondsToSelector:@selector(captureManager:didFailWithError:)]) {
                                            [[self delegate] captureManager:self didFailWithError:error];
                                        }                                           
                                    }

                                    if ([[UIDevice currentDevice] isMultitaskingSupported]) {
                                        [[UIApplication sharedApplication] endBackgroundTask:[self backgroundRecordingID]];
                                    }

                                    if (assetURL!=nil)
                                    {
                                        if ([[self delegate] respondsToSelector:@selector(captureManagerRecordingFinished:)]) {
                                        [[self delegate] captureManagerRecordingFinished:self];
                                        }
                                    }
                                    else
                                    {
                                        NSLog(@"Video is not saved");
                                        NSString *alertMsg = [NSString stringWithFormat:@"Impossible to copy video to photo album"];
                                        UIAlertView *alert = [[UIAlertView alloc] init];
                                        [alert setTitle:@"info"];
                                        [alert setMessage:alertMsg];
                                        [alert setDelegate:self];
                                        [alert addButtonWithTitle:@"Accept"];
                                        [alert show];
                                    }
                                }];
     }
}
+4
source share
2 answers

I have almost the same problem: I'm just trying to save photos, not movies; but still assetURL is NULL. Here is my code:

    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

ALAssetsLibrary *library = [[ALAssetsLibrary alloc]init];
[library writeImageToSavedPhotosAlbum:(__bridge CGImageRef)([info objectForKey:UIImagePickerControllerOriginalImage])
                          orientation:ALAssetOrientationUp completionBlock:^(NSURL *assetURL, NSError *error) {
                              if(error == nil) {
                                  _myImageUrl = [NSString stringWithFormat:@"%@",assetURL];
                                  NSLog(@"%@",assetURL);
                              } else NSLog(@"%@",error);
                          }];

[picker dismissViewControllerAnimated:YES completion:nil];
}

So, I think this problem is not related to file size.

+1
source

, 2 . iPhone, 7Gb, 3,2 (3,8 ) . 2Gb, . ?. , , , , .

, IOS7 writeVideoAtPathToSavedPhotosAlbum, ALAssetsLibraryWriteDiskSpaceError = -3305. , IOS- ... IOS7 .

, . - , .

.

ADD: FYI, 4Gb (4.6Gb) IOS 7.0.3

0

All Articles