Reopening AVCaptureSession

I have an application that takes some snapshots. My entire application is based on the AVCam sample code from WWDC 2010. I have mixed up a lot with this, but still I can’t figure out how to format the camera correctly, which frees up the camera session ...

All I'm trying to do is the following:

  • Open camera view controller
  • Take some photos
  • Close the camera controller.
  • Open it again

The second time I click viewController, the session is lost, the preview is not available, and the capture is also not available. I posted a complete sample code on github .

My workaround for the problem was to not release the camera at all, so the camera view controller acts like Singleton, which, in my opinion, is not the right way. Moreover, with this behavior, I could not understand how to support the camera when the application moved to the background (for example, a phone call).

Please advice . How to destroy a camera session? and is it important to do this?

+5
source share
2 answers

I added the following message AVCamCaptureManager

- (void) destroySession {

    if ([delegate respondsToSelector:@selector(captureManagerSessionWillEnd:)]) {
        [delegate captureManagerSessionWillEnd:self];
    }

    // remove the device inputs
    [session removeInput:[self videoInput]];
    [session removeInput:[self audioInput]];

    // release
    [session release];

    // remove AVCamRecorder
    [recorder release];

    if ([delegate respondsToSelector:@selector(captureManagerSessionEnded:)]) {
        [delegate captureManagerSessionEnded:self];
    }
}

I call destroySessionwhen the viewController holding the camera approaches (in my example, this is -closeCamera:from AVCamViewController).

AVCam-CameraReleaseTest github.com

+5

All Articles