2012-04-12 42 views
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]; 

回答

0

你需要觀察你的AVCaptureSession利用志願的interrupt標誌,並在其反應。

AVCaptureSession Reference

interrupted 

指示接收器是否已經中斷。 (只讀)

@property(nonatomic, readonly, getter=isInterrupted) BOOL interrupted 
Discussion 

您可以觀察使用鍵 - 值觀察

可提供的iOS 4.0和更高版本此屬性的值。聲明在AVCaptureSession.h

+4

你如何反應呢? – Alper 2012-05-29 16:19:41