문제

I am using the AV Foundation for capturing images continuously after Apple released iOS 4.0 by following the codes given by, http://developer.apple.com/iphone/library/qa/qa2010/qa1702.html

However, when I call "[session startRunning];" it takes around 1-2 seconds to start the camera preview. So, this is frustrating to the end user as he needs to wait for some time.

Is there a way to Pause the session instead of stopping it since I can init the session at program launch and keep it pause until user navigates to the camera screen and start running it there ? Thanks for any help.

도움이 되었습니까?

해결책

There is no way to "pause" the session, but you can start the capture session running at any time and just leave it running. If you are capturing still images, just call captureStillImageAsynchronouslyFromConnection when you're ready. If you're capturing video, you can have your captureOutput:didOutputSampleBuffer:fromConnection: method in the delegate just throw away frames until you want to do something with them. You might even be able to start the capture session without an output device until you're ready (haven't tried that).

다른 팁

Instead of pausing your session you can rather disable input connection.

e.g.

<your_video_preview_layer>.connection.enabled = NO;

so that it will not consume the data from the input device.

Hope this is what you're looking for.

This is what I did to prevent the UI from locking up the initial 1-2 seconds when calling -startRunning.

1) Add UIActivityIndicator
2) Add observer to AVCaptureSession
3) call -startRunning in a background thread
4) Resume the UI in the notification callback
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top