【问题标题】:Checking if any AV devices are connected检查是否连接了任何 AV 设备
【发布时间】:2015-09-27 22:45:06
【问题描述】:

我有这段代码假设 AV 决定已连接...

AVCaptureDeviceInput *device_input = [[AVCaptureDeviceInput alloc] initWithDevice :
                                              [AVCaptureDevice devicesWithMediaType : AVMediaTypeVideo][0] error : nil];

如何修改该代码以便收到这样的消息...

if (No AV devices were detected)
NSLog(@"No AV devices were detected");
else
NSLog(@"The following devices were detected...");

谢谢, 伦。

【问题讨论】:

    标签: objective-c avkit


    【解决方案1】:

    如果您必须检查音频设备,您可以使用以下代码 -

    -(void)checkForDevice{
        AVCaptureDevice *audioDevice = [[AVCaptureDevice devicesWithMediaType:AVMediaTypeAudio] firstObject];
        AVCaptureDeviceInput *audioDeviceInput = [AVCaptureDeviceInput deviceInputWithDevice:audioDevice error:&error];
    
         if (error)
         {
            NSLog(@"%@", error); //problem with the device
         }
         else
         {
             //device is available  
         }
    }
    

    您可以通过类似的方式检查视频和其他 AV 设备。

    【讨论】:

    • 谢谢,(我是 XCODE 和 Stackoverflow 的新手),我使用了你的建议,但我得到了这个 [AVCaptureDeviceInput deviceInputWithDevice : videoDevice error : &error]; //使用未声明的标识符'error'
    • 谢谢。这将检查内置设备。我如何修改它以检查连接到 Mac 的其他设备。我正在使用 Video2PC 数字转换器连接到数码相机并通过 USB 端口?
    • 好的,我已经放弃了那个数字转换器,现在正在使用有效的火线连接。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-31
    • 1970-01-01
    • 1970-01-01
    • 2015-06-16
    • 2013-02-19
    相关资源
    最近更新 更多