检查是否连接了任何 AV 设备

Checking if any AV devices are connected

我有这段代码,假设已连接 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...");

谢谢, 伦.

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

-(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 设备。