2012-04-12 8 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

にあなたはKVOを使用してAVCaptureSessioninterruptフラグを観察し、それに反応する必要があります、次のように私は、キャプチャセッションを初期化しています。 AVCaptureSession Referenceから

interrupted 

は、受信機が中断されたかどうかを示します。 (読み取り専用)

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

をあなたは、iOS 4.0以降で利用可能

をキー値監視を使用して、このプロパティの値を観察することができます。 AVCaptureSession.hで宣言しました

+4

どのように反応しますか? – Alper

関連する問題