我使用 AVAssetWriter AVCaptureSession 来录制视频。它运行良好。我使用 UIApplicationDidEnterBackgroundNotification 和 CTCallCenter.callEventHandler 在应用程序进入后台或来电时停止记录。UIApplicationDidEnterBackgroundNotification 运行良好。但在 CTCallCenter.callEventHandler,[AVAssetWriter finishWriting] 返回 NO 。这是 AVAssetWriter.error:
Error Domain=AVFoundationErrorDomain Code=-111800 "这个操作无法完成" UserInfo=0x6c0bc20 {NSLocalizedFailureReason=发生未知错误(-12785), NSUnderlyingError=0x6c0fc80 "The operation could not be completed. (OSStatus error -12785.)", NSLocalizedDescription=本次操作无法完成}
来电时似乎 AVAssetWriter 立即失败。录制的文件未完成,无法播放。有人能告诉我怎么处理吗?
CTCallCenter 代码:
m_callCenter = [[CTCallCenter alloc] init];
m_callCenter.callEventHandler= ^(CTCall* call)
{
if (call.callState == CTCallStateDialing || call.callState == CTCallStateIncoming){
[self stopRecording];
//[self performSelectorOnMainThread:@selector(stopRecording) withObject:nil waitUntilDone:NO];
}
};
stopRecording 在其他情况下工作正常。