1

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];
4

1 に答える 1

0

interruptKVOを使用していることのフラグを観察し、AVCaptureSessionそれに反応する必要があります。

AVCaptureSessionリファレンスから:

interrupted

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

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

Key-Value監視を使用して、このプロパティの値を監視できます

iOS4.0以降で利用できます。AVCaptureSession.hで宣言

于 2012-04-12T14:25:07.503 に答える