我正在使用增强现实应用,该应用使用AVCaptureVideoPreviewLayer
来显示来自设备相机的视频。如果您关闭并重新打开应用程序(通过按主页按钮,而不是强制退出)或将手机置于睡眠状态然后将其唤醒,AVCaptureVideoPreviewLayer
将显示黑色矩形而不是相机的进纸。
我正在viewDidLoad:
captureSession = [[AVCaptureSession alloc] init];
AVCaptureDevice *videoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if (videoDevice) {
NSError *error;
AVCaptureDeviceInput *videoIn = [AVCaptureDeviceInput deviceInputWithDevice:videoDevice error:&error];
if (!error) {
if ([captureSession canAddInput:videoIn])
[captureSession addInput:videoIn];
else
NSLog(@"Couldn't add video input");
} else
NSLog(@"Couldn't create video input");
} else
NSLog(@"Couldn't create video capture device");
[captureSession startRunning];
AVCaptureVideoPreviewLayer *previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:captureSession];
previewLayer.frame = cameraView.bounds;
previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
[[cameraView layer] addSublayer:previewLayer];
答案 0 :(得分:0)
您需要使用KVO观察interrupt
的{{1}}标志并对其做出反应。
AVCaptureSession
指示接收器是否已被中断。 (只读)
interrupted
您可以使用键值观察
来观察此属性的值适用于iOS 4.0及更高版本。在AVCaptureSession.h中声明