QTKit,打开输入设备?
我试图在以下内容中向 QTCaptureSession 添加两个输入:
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];
我已确定注释掉的部分是错误的来源:
[QTCaptureDeviceInput initWithDevice:]-
无法使用未打开的设备初始化设备输入。
我在开放方法之后探测了我的“成功”变量,结果是肯定的。 那么为什么该方法认为设备未打开呢?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(1)
如果您还没有找到答案,我认为您的问题实际上出在您指出的两行上方。 我检查了 Apple 的文档,发现 QTMediaTypeSound 和 QTMediaTypeVideo 是常量,而不是您应该手动传入的字符串。例如,快速的 NSLog() 语句显示 QTMediaTypeVideo 常量实际上等于“vide”。
简而言之,您的代码应该是:
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: