Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error when capturing camera and audio input

using some of the nifty new APIs in iOS4 i am trying to capture input from the iPhone's camera and microphone and save it to a file. below is the code i am using.

AVCaptureSession* captureSession = [[AVCaptureSession alloc] init];
AVCaptureDevice *audioCaptureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];
AVCaptureDeviceInput *audioInput = [AVCaptureDeviceInput deviceInputWithDevice:audioCaptureDevice error:&error];
AVCaptureDeviceInput* videoInput = [[AVCaptureDeviceInput alloc] initWithDevice:captDevice error:&error];
AVCaptureMovieFileOutput * videoOutput = [[AVCaptureMovieFileOutput alloc] init];

if (videoInput && videoOutput && audioInput) 
{
    [captureSession addInput:audioInput];
    [captureSession addInput:videoInput];
    [captureSession addOutput:videoOutput];
    if([captDevice lockForConfiguration:&error])
    {
        if ([captDevice hasTorch]) 
            captDevice.torchMode = AVCaptureTorchModeOn;

        [captDevice unlockForConfiguration];
    }
    else 
    {
        NSLog(@"Could not lock device for config error: %@", error);
    }

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];

    NSURL* saveLocationURL = [[NSURL alloc] initFileURLWithPath:[NSString stringWithFormat:@"%@/movie.mov", documentsDirectory]];

    [videoOutput startRecordingToOutputFileURL:saveLocationURL recordingDelegate:self];
    [captureSession startRunning];

    [saveLocationURL release];
}
else 
{
    NSLog(@"Video Error: %@", error);
}   

when the didFinishRecordingToOutputFileAtURL comes back i get a cryptic error response.

Error Domain=AVFoundationErrorDomain Code=-11803 "Cannot Record" UserInfo=0x152f70 {NSLocalizedRecoverySuggestion=Try recording again., AVErrorRecordingSuccessfullyFinishedKey=false, NSLocalizedDescription=Cannot Record}

the error code −11803 means "AVErrorSessionNotRunning". all i can say is tell me something i don't know. anyone have any idea why the session is not running?

like image 217
iHorse Avatar asked Aug 16 '10 17:08

iHorse


Video Answer


1 Answers

Call [captureSession startRunning]; before [videoOutput startRecordingToOutputFileURL:saveLocationURL recordingDelegate:self];.

like image 52
tc. Avatar answered Sep 18 '22 14:09

tc.