Tutorial :QTKit, opening input devices?



Question:

I'm trying to add two inputs to a QTCaptureSession in the following:

mainSession = [[QTCaptureSession alloc] init];    BOOL success;  NSError* error;    QTCaptureDevice *videoDevice = [QTCaptureDevice defaultInputDeviceWithMediaType:@"QTMediaTypeVideo"];  success = [videoDevice open:&error];    QTCaptureDevice *audioDevice = [QTCaptureDevice defaultInputDeviceWithMediaType:@"QTMediaTypeSound"];  success = [audioDevice open:&error];    //video = [[QTCaptureDeviceInput alloc] initWithDevice:videoDevice];  //success = [mainSession addInput:video error:&error];    //audio = [[QTCaptureDeviceInput alloc] initWithDevice:audioDevice];  //success = [mainSession addInput:audio error:&error];    output = [[QTCaptureMovieFileOutput alloc] init];  success = [mainSession addOutput:output error:&error];    [output setDelegate:self];    [movieView setCaptureSession:mainSession];    [mainWindow makeKeyAndOrderFront:NSApp];    [mainSession startRunning];  

I've determined that the commented out part is the sources of the error:

[QTCaptureDeviceInput initWithDevice:]- cannot intialize device input with device that is not open.

I've probed my "success" variable after the open methods and it is yes. So why does the method think the device isn't open?


Solution:1

If you haven't found an answer yet, I think your problem is actually in the lines above the two you indicated. I checked Apple's documentation, and found that QTMediaTypeSound and QTMediaTypeVideo are constants, not strings you should manually pass in. A quick NSLog() statement reveals, for example, that the QTMediaTypeVideo constant is actually equal to "vide".

In short, your code should be:

mainSession = [[QTCaptureSession alloc] init];    BOOL success;  NSError* error;    QTCaptureDevice *videoDevice = [QTCaptureDevice defaultInputDeviceWithMediaType:QTMediaTypeVideo];  success = [videoDevice open:&error];    QTCaptureDevice *audioDevice = [QTCaptureDevice defaultInputDeviceWithMediaType:QTMediaTypeSound];  success = [audioDevice open:&error];    video = [[QTCaptureDeviceInput alloc] initWithDevice:videoDevice];  success = [mainSession addInput:video error:&error];    audio = [[QTCaptureDeviceInput alloc] initWithDevice:audioDevice];  success = [mainSession addInput:audio error:&error];    output = [[QTCaptureMovieFileOutput alloc] init];  success = [mainSession addOutput:output error:&error];    [output setDelegate:self];    [movieView setCaptureSession:mainSession];    [mainWindow makeKeyAndOrderFront:NSApp];    [mainSession startRunning];  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »