开发者

Reopening AVCaptureSession

开发者 https://www.devze.com 2023-04-12 22:40 出处:网络
I have an application which takes some pictures. My whole application is开发者_Go百科 based on the AVCam sample code from WWDC 2010.

I have an application which takes some pictures. My whole application is开发者_Go百科 based on the AVCam sample code from WWDC 2010. I've messed with it a lot and yet, up until now I can't figure out how to release the camera view properly which releases the camera session...

All i'm trying to do is the following:

  • Open camera view controller
  • Take some photos
  • Close camera view Controller
  • Open it again

The second time I push the viewController the session is lost, preview is not available and capturing is not available as well. I've published full example code on github.

My workaround for the issue was not to release the camera at all so the Camera View Controller acts as a Singleton, which I think is not the right way. moreover, with this behavior I couldn't figure out a way to support camera when application went to the background (phone call for example).

Please advice. How do I destruct the camera session? and is it important to do so?


I've added the following message to 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'm calling destroySession when the viewController holding the camera get close (on my example it's -closeCamera: of AVCamViewController).

For the full working example, you're welcome to download AVCam-CameraReleaseTest on github.com


G

I think that may help you have a look .

http://red-glasses.com/index.php/tutorials/ios4-take-photos-with-live-video-preview-using-avfoundation/

0

精彩评论

暂无评论...
验证码 换一张
取 消