重新打开AVCaptureSession [英] Reopening AVCaptureSession

查看:248
本文介绍了重新打开AVCaptureSession的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,需要一些图片。
我的整个应用程序基于来自WWDC 2010的 AVCam 示例代码。
我搞错了很多,直到现在我不知道如何正确释放相机视图,释放相机会话...



我想要做的是以下内容:




  • 打开相机视图控制器

  • 拍摄一些照片

  • 关闭相机视图控制器

  • 再次打开



第二次我推viewController会话丢失,预览不可用,捕获也不可用。我已在github上发布完整示例代码



我的问题的解决方法是不是释放相机,所以相机视图控制器作为一个Singleton,我认为是正确的方式。此外,有了这种行为,我不能找出一种方法来支持相机,当应用程序转到背景(例如电话)。



请咨询。如何破坏相机会话?

我已经添加了以下消息到 AVCamCaptureManager

code>

   - (void)destroySession {

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

//删除设备输入
[session removeInput:[self videoInput]];
[session removeInput:[self audioInput]];

// release
[session release];

// remove AVCamRecorder
[recorder release];

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

我调用 destroySession c> >)。



对于完整的工作示例,欢迎您下载 github.com上的AVCam-CameraReleaseTest


I have an application which takes some pictures. My whole application is 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

这篇关于重新打开AVCaptureSession的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆