Search code examples
iosobjective-cavfoundationavcam

How to pause video recording in ios application (objective-c)


Using AVCam I'm abel to start and stop video recording. This method to start recording:

-(void)captureOutput:(AVCaptureFileOutput *)captureOutput didStartRecordingToOutputFileAtURL:(NSURL *)fileURL fromConnections:(NSArray *)connections;

and to stop recording :

-(void)captureOutput:(AVCaptureFileOutput *)captureOutput didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL fromConnections:(NSArray *)connections error:(NSError *)error;

My question is how can I pause recording? looking into the AVFoundation I can found a pause method which is :

-(void)captureOutput:(AVCaptureFileOutput *)captureOutput didPauseRecordingToOutputFileAtURL:(NSURL *)fileURL fromConnections:(NSArray *)connections

but I can't find a way to make it function. I searched a lot but nothing seemed to solve my problem, so please help. Thank you in advance.


Solution

  • What about changing the method From AVCam to CameraEngine?

        #import "CameraEngine.h"
    
    
    - (void) startPreview
    {
        AVCaptureVideoPreviewLayer* preview = [[CameraEngine engine] getPreviewLayer];
        [preview removeFromSuperlayer];
        preview.frame = self.cameraView.bounds;
        [[preview connection] setVideoOrientation:UIInterfaceOrientationLandscapeRight];
    
        [self.cameraView.layer addSublayer:preview];
    }
    
    
    
        - (IBAction)startRecording:(id)sender
        {
            [[CameraEngine engine] startCapture];
        }
    
        - (IBAction)pauseRecording:(id)sender
        {
            [[CameraEngine engine] pauseCapture];
        }
    
        - (IBAction)stopRecording:(id)sender
        {
            [[CameraEngine engine] stopCapture];
        }
        - (IBAction)resumeRecording:(id)sender
        {
            [[CameraEngine engine] resumeCapture];
        }