ALAssetsLibraryWriteVideoCompletionBlock return undefined values

假如想象 提交于 2019-12-10 15:43:20

问题


ALAssetsLibraryWriteVideoCompletionBlock is returning undefined values. If assetURL is equal to nil, then error ought to be not equal to nil, that is, return to me some error description.

See apple documentation at here.

When I record small video, ALAssetsLibraryWriteVideoCompletionBlock return a good value of assetURL, but when I record long video 3 or 4 Gb, assetURL return nil and error return nil. Video recorded is in tmp file because I can see this video in temporally folder in my app. It seems like IOS framework try to do a copy of this temporally file to photo album and iPhone don't have enough memory to copy this temp file to photo album and return a path of this file (assetURL).

Is this a bug in iOS framework? If so, is there a way to fix it?

UPDATE: My files is less than 4GB. 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's 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];
                                    }
                                }];
     }
}

回答1:


I have almost the same issue: just that I try 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 guess this issue is not related to the size of the file..




回答2:


I do different tests and I can save videos with more than 2Gb. In this case I delete a lot of files in my iPhone until I had 7Gb, then I saved a video with 3.2Gb (3.8Gb free) and store in photo gallery. Then I saved other video with 2Gb and it didn't save in photo gallery. What does it means?. Well, when you are saving a temp video, then you need at least the same or more free space than the video that you are trying to copy to photo gallery.

The problem here is that IOS7 framework doesn't return any error with his function writeVideoAtPathToSavedPhotosAlbum, in this case it have to return ALAssetsLibraryWriteDiskSpaceError = -3305. Maybe in previous version of IOS framework it works...but in IOS7 not.

By the way, I open a ticket in apple bug reporter. If they tell me something different I will post it.

Thanks for all guys.

ADD: FYI, I save a video file with more than 4Gb (4.6Gb) in IOS 7.0.3



来源:https://stackoverflow.com/questions/20813540/alassetslibrarywritevideocompletionblock-return-undefined-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!