CoreMediaIO, incorrectly updated properties kCMIODevicePropertyDeviceIsRunningSomewhere
Asked Answered
G

1

2

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);
}
Gualtiero answered 8/3, 2017 at 20:17 Comment(0)
Z
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

Zanezaneski answered 8/7, 2017 at 14:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.