问题
I need to receive an event when some process starts using the camera. I did this through CMIOObjectGetPropertyData. But it does not work correctly, the correct value is only the first time it is accessed.
I also tried to use the CMIOObjectAddPropertyListenerBlock but he did not work it from me. Tell me please, what am I doing wrong? I will be very grateful.
while (1)
{
UInt32 value = 0;
UInt32 valuePropertySize = sizeof(flag);
CMIOObjectPropertyAddress opa = {kCMIODevicePropertyDeviceIsRunningSomewhere,
kAudioObjectPropertyScopeWildcard, kAudioObjectPropertyElementMaster};
OSStatus result = CMIOObjectGetPropertyData(device, &opa, 0, NULL, sizeof(UInt32), &valuePropertySize, &value);
NSLog(@"%d : %d", result, value);
sleep(1);
}
回答1:
I also had the same problem. Getting data with CMIOObjectGetPropertyData
worked but registering a listener block with CMIOObjectAddPropertyListenerBlock
never received any event.
The solution to the issue was totally unrelated to the CMIO* code. Basically, I forgot to start the run loop, and that prevented receiving events.
Please take a look here: currentRunLoop
Adding a simple [[NSRunLoop currentRunLoop] run];
fixed the issue for me
来源:https://stackoverflow.com/questions/42681127/coremediaio-incorrectly-updated-properties-kcmiodevicepropertydeviceisrunningso