Home:ALL Converter>delaying picture capture in AVCam demo

delaying picture capture in AVCam demo

Ask Time:2012-07-08T03:15:46         Author:michael

Json Formatter

Using the AVCam demo, I'm trying to add a delay of 5 seconds before the picture is actually taken by making the following changes in AVCamViewController.m:

- (IBAction)captureStillImage:(id)sender
{
    // Capture a still image
    [[self stillButton] setEnabled:NO];

    // delay picture capture by 5 seconds
myTimer = [NSTimer scheduledTimerWithTimeInterval: 5.0                                                
        target: self                                                  
        selector: @selector(pictureTimer:)                                          
        userInfo: nil                                                
        repeats: NO];
}

- (void) pictureTimer: (NSTimer *) timer {
    [[self captureManager] captureStillImage];
}

However, the completion handler in AVCamCaptureManager::captureStillImage never seems to get called (I never see the "captureStillImage completion handler" log message):

- (void) captureStillImage
{
    AVCaptureConnection *stillImageConnection = [AVCamUtilities connectionWithMediaType:AVMediaTypeVideo fromConnections:[[self stillImageOutput] connections]];
    if ([stillImageConnection isVideoOrientationSupported])
        [stillImageConnection setVideoOrientation:orientation];

    NSLog(@"captureStillImage");
    [[self stillImageOutput] captureStillImageAsynchronouslyFromConnection:stillImageConnection
         completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {
             NSLog(@"captureStillImage completion handler");

Will this just not work using an NSTimer?

Author:michael,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/11377933/delaying-picture-capture-in-avcam-demo
yy