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

时间:2015-09-27 22:45:07

标签: objective-c avkit

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

谢谢, LEN。

1 个答案:

答案 0 :(得分: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设备。