CoreMediaIO, incorrectly updated properties kCMIODevicePropertyDeviceIsRunningSomewhere

南笙酒味 提交于 2021-02-10 07:38:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!