【发布时间】:2013-12-16 12:29:05
【问题描述】:
我一直在寻找答案 2 天,但我似乎无法正确...
我有一个示例应用程序,它使用 AVCaptureSession 和 AVCaptureMovieFileOutput 从设备录制音频和视频。
当我开始录音时,我会打电话:
[self.movieFileOutput startRecordingToOutputFileURL:outputURL recordingDelegate:self];
它开始记录到文件中。如果我再次按下按钮,它将停止录制
[self.movieFileOutput stopRecording];
一切正常,但是当我进入后台(来电或按 HOME)时,委托方法中出现错误:didFinishRecordingToOutputFileAtURL
我想要的操作应该是在进入后台时保存/完成文件。如果我在“applicationDidEnterBackground”上调用 stopRecording,它将在调用 applicationDidEnterBackground 之前进入后台。在进入活动状态时,它被调用....并生成错误并留下损坏的电影文件...
似乎没有足够的时间来保存文件。
我在这里错过了什么?
这是我的错误
Error Domain=AVFoundationErrorDomain Code=-11818 "Recording Stopped" UserInfo=0x17594e20 {NSLocalizedRecoverySuggestion=Stop any other actions using the recording device and try again., NSUnderlyingError=0x175d3500 "The operation couldn’t be completed. (OSStatus error -16133.)", NSLocalizedDescription=Recording Stopped}
AVErrorSessionWasInterrupted = -11818
【问题讨论】:
-
我也试过 Apple AVDemo 应用程序,它也给出了同样的错误。似乎无论如何都会抛出错误。不同之处在于,在 Apple 的代码中,他们有时间使用 UIBackgroundTaskIdentifier 执行大量代码
标签: ios camera avcapturesession avcapturemoviefileoutput