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]) {
[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];
}
}];
}
}
c4esp source
share