我使用AVAssetWriter AVCaptureSession来录制视频.工作得很好.我使用UIApplicationDidEnterBackgroundNotification和CTCallCenter.callEventHandler在应用程序进入后台或来电时停止记录.UIApplicationDidEnterBackgroundNotification工作正常.但在CTCallCenter.callEventHandler中,[AVAssetWriter finishWriting]返回NO.这是AVAssetWriter.error:
Error Domain = AVFoundationErrorDomain Code = -11800"这项操作无法完成"UserInfo = 0x6c0bc20 {NSLocalizedFailureReason =发生未知错误(-12785),NSUnderlyingError = 0x6c0fc80"操作无法完成.(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];
}
};
Run Code Online (Sandbox Code Playgroud)
stopRecording在其他情况下工作正常.
电话会导致AudioSession中断,因此如果您使用AudioSession回叫,您可能会更快发现.虽然我怀疑你此时AVAssetWriter可能已经被炸了.
设置AVAssetWriter.movieFragmentInterval应该有助于最大限度地减少损失 - 来自AVAssetWriter.h:
使用影片片段时,可以成功打开写入意外中断的部分书写资源,并播放指定时间间隔的倍数.
| 归档时间: |
|
| 查看次数: |
1402 次 |
| 最近记录: |