I'm doing a basic application on Objective-C and the AVFoundation framework, I wanna detect if the built in camera for Mac is being used by another application, I have managed to do it, but it always returns false even when I'm using the camera with another software.
I have a function that wraps this code and is executed every 2 seconds:
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]);
}
The problem is, I always get the same result:
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)
EDIT
The camera that appears on the software it's the same that this one, and I only have the built-in camera of the MacBook Pro.
Thanks in advance!
EDIT
The softwares that I have used to use the camera are:
- Hangouts
- Skype
- RedBooth
- Slack
As mentioned in the below link, it will return true only if some other app is exclusively using the camera:
https://developer.apple.com/reference/avfoundation/avcapturedevice/1389512-isinusebyanotherapplication
And that exclusive lock is acquired like below:
https://developer.apple.com/reference/avfoundation/avcapturedevice/1387810-lockforconfiguration
Clarification: key word is exclusive. The camera can only be exclusively locked via
lockForConfiguration
, and that's only temporary. So, multiple apps can use the camera at the same time.