我正在尝试创建一个可以将视频录制到文件中的应用。我使用此文档文件作为指南:Apple documentation。当视频持续时间达到其允许的最大持续时间时,会出现此问题。这是我设置最长持续时间的方式:
self.avOutput = [[AVCaptureMovieFileOutput alloc] init];
self.avOutput.maxRecordedDuration = CMTimeMake(5 * 20, 20);
然后调用此方法并开始出现问题:
- (void)captureOutput:(AVCaptureFileOutput *)captureOutput
didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL
fromConnections:(NSArray *)connections
error:(NSError *)error
{
BOOL recordedSuccessfully = YES;
if ([error code] != noErr) {
// A problem occurred: Find out if the recording was successful.
id value = [[error userInfo] objectForKey:AVErrorRecordingSuccessfullyFinishedKey];
if (value) {
recordedSuccessfully = [value boolValue];
}
}
// some code...
}
因此,此方法调用:[[error userInfo] objectForKey:AVErrorRecordingSuccessfullyFinishedKey]
返回nil
作为结果,我无法检查录制是否定期完成。
这很奇怪,因为我没有找到涵盖这个特定案例的文档的任何部分。 这是打印错误日志时得到的结果:
(lldb) po error
Error Domain=AVFoundationErrorDomain Code=-11810 "Recording Stopped" UserInfo=0x146443c0 {AVErrorTimeKey=CMTime: {100/20 = 5.000}, NSLocalizedFailureReason=The recording reached the maximum allowable length., NSLocalizedDescription=Recording Stopped, NSUnderlyingError=0x1463edb0 "The operation couldn’t be completed. (OSStatus error -16132.)"}
(lldb) po error.userInfo
{
AVErrorTimeKey = "CMTime: {100/20 = 5.000}";
NSLocalizedDescription = "Recording Stopped";
NSLocalizedFailureReason = "The recording reached the maximum allowable length.";
NSUnderlyingError = "Error Domain=NSOSStatusErrorDomain Code=-16132 \"The operation couldn\U2019t be completed. (OSStatus error -16132.)\"";
}
有人可以帮我解决这个问题吗?
谢谢!
答案 0 :(得分:0)
嘿,我不确定您是否找到了解决此问题的方法,但我通过检查录制视频的大小来解决此问题,使用
@property(nonatomic, strong) NSData *getVideo;
如下:
//At the end of the method above add:
getVideo = [NSData dataWithContentsOfURL:outputFileURL];
NSLog(@" size of getVideo %lu in bytes", (unsigned long)getVideo.length);
这将检查录制视频的大小。我希望这可以帮到你。你有没有找到更好的方法来解决这个问题?谢谢!