Hola estoy intentando grabar video con AVCaptureSession y AVCaptureMovieFileOutput, pero al agregar la entrada de audio y video no se activan las conexiones.
Éste es el código
Código:
session = [[AVCaptureSession alloc] init];
[session beginConfiguration];
session.sessionPreset = AVCaptureSessionPresetPhoto;
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
AVCaptureDevice *audioDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:nil];
AVCaptureDeviceInput *audioInput = [AVCaptureDeviceInput deviceInputWithDevice:audioDevice error:nil];
NSError *error;
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryRecord error:&error];
[audioSession setActive:YES error:&error];
[session addInput:input];
[session addInput:audioInput];
MovieFileOutput = [[AVCaptureMovieFileOutput alloc] init];
[session addOutput:MovieFileOutput];
Después simplemente hago esto para iniciar la grabación
Código:
NSString *outputPath = [[NSString alloc] initWithFormat:@"%@%@", NSTemporaryDirectory(), @"output2.mov"];
NSURL *outputURL = [[NSURL alloc] initFileURLWithPath:outputPath];
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:outputPath])
{
NSError *error;
if ([fileManager removeItemAtPath:outputPath error:&error] == NO)
{
NSLog(@"error %@",error);
//Error - handle if requried
}
}
//Start recording
@try{
NSLog(@"grabando...");
[MovieFileOutput startRecordingToOutputFileURL:outputURL recordingDelegate:self];
alreadyGrabando = YES;
}@catch(NSException *e){}
Pero siempre me da lanza la excepción:
Código:
exception *** -[AVCaptureMovieFileOutput startRecordingToOutputFileURL:recordingDelegate:] - no active/enabled connections.
Y al checar las entradas de audio y video:
Código:
"<AVCaptureConnection: 0x124799c50 [type:vide][enabled:1][active:0]>",
"<AVCaptureConnection: 0x124794110 [type:soun][enabled:1][active:0]>"
¿Alguien sabe cómo activar las entradas?