1
我正在使用增強現實應用程序,該應用程序使用AVCaptureVideoPreviewLayer
來顯示設備攝像頭的視頻源。如果您關閉並重新打開應用程序(通過按主頁按鈕而不是強制戒菸),或者讓手機進入休眠狀態然後將其喚醒,則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];
你如何反應呢? – Alper 2012-05-29 16:19:41