AVCaptureDevice isInUseByAnotherApplication始终返回false

时间:2017-01-06 19:03:22

标签: objective-c avfoundation avcapturedevice

我正在Objective-C和AVFoundation框架上做一个基本的应用程序,我想检测一下Mac的内置摄像头是否被另一个应用程序使用,我已经设法做到了,但它总是返回false,即使是我正在使用相机和其他软件。

我有一个包装此代码的函数,每2秒执行一次:

NSArray *devices =  [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
    for(AVCaptureDevice *camera in devices){
        NSLog([camera isInUseByAnotherApplication] ? @"YES DEVICE BEING USED": @"DEVICE NOT BEING USED");
        NSLog([camera isSuspended] ? @"YES DEVICE SUSPENDED": @"DEVICE NOT suspended");
        NSLog([camera manufacturer]);
        NSLog([camera localizedName]);

    }

问题是,我总是得到相同的结果:

2017-01-06 13:02:24.657 Befective Agent[13749:175226] DEVICE NOT BEING USED
2017-01-06 13:02:24.658 Befective Agent[13749:175226] DEVICE NOT suspended
2017-01-06 13:02:24.658 Befective Agent[13749:175226] Apple Inc.
2017-01-06 13:02:24.658 Befective Agent[13749:175226] FaceTime HD Camera (Built-in)

修改

软件上出现的相机与此相机相同,而且我只有MacBook Pro的内置相机。

提前致谢!

修改

我以前使用相机的软件是:

  • 环聊
  • 的Skype
  • RedBooth
  • 松弛

1 个答案:

答案 0 :(得分:3)

如下面的链接所述,只有当其他应用专门使用相机时,它才会返回true:

How do I check if a C++ string is an int?

如下所示获得独占锁:

https://developer.apple.com/reference/avfoundation/avcapturedevice/1389512-isinusebyanotherapplication