ALAssetsLibraryWriteVideoCompletionBlock
返回未定义的值。如果 assetURL 等于 nil,那么 error 应该不等于 nil,即返回给我一些错误描述。
请参阅苹果文档:here https://developer.apple.com/library/ios/documentation/AssetsLibrary/Reference/ALAssetsLibrary_Class/Reference/Reference.html#//apple_ref/c/tdef/ALAssetsLibraryWriteVideoCompletionBlock.
当我录制小视频时,ALAssetsLibraryWriteVideoCompletionBlock
返回一个很好的 assetURL 值,但是当我录制 3 或 4 Gb 的长视频时,assetURL 返回 nil 并且错误返回 nil。录制的视频位于 tmp 文件中,因为我可以在应用程序的临时文件夹中看到该视频。看起来 iOS 框架尝试将此临时文件复制到相册,而 iPhone 没有足够的内存来将此临时文件复制到相册并返回此文件的路径 (assetURL)。
这是iOS框架中的一个错误吗?如果是这样,有办法解决吗?
更新:
我的文件小于 4GB。谢谢
更新源代码:
-(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。这是我的代码:
- (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];
}
所以,我想这个问题与文件的大小无关。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)