動画をキャプチャして保存する機能を備えたアプリを作成しました。私はそのためにAVFoundationを使用し、AppleのAVCamが私のガイドでした。
明確にできると
いいのですが、AVCamCaptureManagerを処理するvideoViewControllerを初めてリリースするまで(AVCamではAVCamViewControllerになります)、すべてが正常に機能します。その後、再度作成すると、カメラ切り替え直後に動画がフリーズします。再実行しても、役に立たず、クリーンアップも、デバイスのリセットも行われません。(場合によっては、1つのことが役立ちますが、それは規則ではありません)。
メモリを節約する必要がない場合は、videoViewControllerを解放します。
カメラを切り替えるためのコードは、基本的にAVCamと同じです。
NSError *error;
AVCaptureDeviceInput *newVideoInput;
AVCaptureDevicePosition position = currentVideoInput.device.position;
if (position == AVCaptureDevicePositionBack)
newVideoInput = [[AVCaptureDeviceInput alloc] initWithDevice:frontFacingCamera error:&error];
else if (position == AVCaptureDevicePositionFront)
newVideoInput = [[AVCaptureDeviceInput alloc] initWithDevice:backFacingCamera error:&error];
if (newVideoInput != nil) {
[session beginConfiguration];
[session removeInput:currentVideoInput];
if ([session canAddInput:newVideoInput]) {
[session addInput:newVideoInput];
[self setVideoInput:newVideoInput];
} else {
[session addInput:currentVideoInput];
}
[session commitConfiguration];
[newVideoInput release];
} else if (error) {
NSLog(@"%@",[error localizedDescription]);
}
videoViewを却下するコード
[self.videoViewController.view removeFromSuperview];
self.videoViewController = nil;
私の現在の「回避策」は、必要がない場合でも、そのままにしておくことです。
誰かがこれが起こっている理由とそれを解決する方法を説明できますか?
編集:
W Dysonが彼の応答で指摘したように、私は次のようにvideoViewControllerをリリースする前にセッションを停止する必要がありました。
[[[self.videoViewController captureManager] session] stopRunning];
[self.videoViewController.view removeFromSuperview];
self.videoViewController = nil;
WDysonに感謝します。