ALAssetsLibraryWriteVideoCompletionBlock返回未定义的值 [英] ALAssetsLibraryWriteVideoCompletionBlock return undefined values

查看:62
本文介绍了ALAssetsLibraryWriteVideoCompletionBlock返回未定义的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ALAssetsLibraryWriteVideoCompletionBlock 返回未定义的值.如果assetURL等于nil,那么错误应该不等于nil,即,向我返回一些错误描述.

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.

请参阅此处.

当我录制小视频时, ALAssetsLibraryWriteVideoCompletionBlock 返回一个好值的assetURL,但是当我录制3或4 Gb长视频时,assetURL返回nil,错误返回nil.录制的视频位于tmp文件中,因为我可以在我的应用程序的临时文件夹中看到该视频.似乎IOS框架尝试将这个临时文件复制到相册,而iPhone没有足够的内存将这个临时文件复制到相册并返回此文件的路径(assetURL).

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).

这是iOS框架中的错误吗?如果是这样,有办法解决吗?

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

更新:我的文件小于4GB.谢谢

UPDATE: My files is less than 4GB. Thanks

使用源代码更新:

    -(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];
                                    }
                                }];
     }
}

推荐答案

我遇到了几乎相同的问题:只是我尝试保存照片,而不是电影.但assetURL仍为NULL.这是我的代码:

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..

这篇关于ALAssetsLibraryWriteVideoCompletionBlock返回未定义的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆