我沉溺了很多时间,所以我想我会转发。
我正在使用AVCaptureSession和AVCaptureMovieFileOutput来允许用户在提供暂停录制按钮的同时录制视频。
这种方法很有效,直到应用程序背景,控制中心被抬起,或者发生警报/呼叫等中断。根据设备硬件的不同,我们会看到一种不同的错误。
在第一种情况下,didStartRecordingToOutputFileAtURL:永远不会被调用。在第二种情况下,didStartRecordingToOutputFileAtURL:将被调用,但didFinishRecordingToOutputFileAtURL:将不会。
目前,我们正在这样做:
- (void)viewDidLoad {
[self initializeCaptureSessionAndOutputData]; //based on your requirements
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.captureSession startRunning];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(interruptionDidOccur)
name:UIApplicationWillResignActiveNotification
object:nil];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.captureSession stopRunning];
[[NSNotificationCenter] defaultCenter] removeObserver:self];
}
- (void)interruptionDidOccur {
[self.movieFileOutput stopRecording]; //expect didFinishRecordingToOutputFileAtURL to be called
}
答案 0 :(得分:0)
问题没有记录,但可以解决。除了打电话
[self.captureSession stopRunning]
:每当触发UIApplicationWillResignActiveNotification通知时也必须调用它。以下是示例代码:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self handleAppReturn];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(becameActive)
name:UIApplicationDidBecomeActiveNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(resignActive)
name:UIApplicationWillResignActiveNotification
object:nil];
}
- (void)resignActive {
[self.videoCameraManager.captureSession stopRunning];
if (!self.isPaused) {
[self pauseVideo];
}
}
- (void)becameActive {
[self.videoCameraManager.captureSession startRunning];
}