0

我有这个代码,它假设一个 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...");

谢谢,莱恩。

4

1 回答 1

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

于 2015-09-28T05:52:12.590 回答