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?
Call [captureSession startRunning]; before [videoOutput startRecordingToOutputFileURL:saveLocationURL recordingDelegate:self];.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With