ошибка при захвате камеры и аудиовхода

с помощью некоторых изящных новых API в iOS4 я пытаюсь захватить ввод с камеры и микрофона iPhone и сохранить его в файл. Ниже приведен код, который я использую.

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);
}   

когда возвращается didFinishRecordingToOutputFileAtURL, я получаю загадочный ответ об ошибке.

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

код ошибки -11803 означает «AVErrorSessionNotRunning». все, что я могу сказать, это сказать мне то, чего я не знаю. кто-нибудь знает, почему сеанс не запущен?

5
задан iHorse 16 August 2010 в 17:58
поделиться