【问题标题】:CoreMediaIO, incorrectly updated properties kCMIODevicePropertyDeviceIsRunningSomewhereCoreMediaIO,错误更新的属性 kCMIODevicePropertyDeviceIsRunningSomewhere
【发布时间】:2024-01-04 23:30:01
【问题描述】:

当某个进程开始使用相机时,我需要接收一个事件。我通过 CMIOObjectGetPropertyData 做到了这一点。 但它不能正常工作,正确的值只有第一次访问。

我也尝试使用 CMIOObjectAddPropertyListenerBlock,但他没有从我这里工作。请告诉我,我做错了什么?我将不胜感激。

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);
}

【问题讨论】:

    标签: objective-c macos cocoa avfoundation isight


    【解决方案1】:

    我也遇到了同样的问题。使用CMIOObjectGetPropertyData 获取数据有效,但使用CMIOObjectAddPropertyListenerBlock 注册侦听器块从未收到任何事件。

    该问题的解决方案与 CMIO* 代码完全无关。 基本上,我忘了启动运行循环,这阻止了接收事件。

    请看这里:currentRunLoop

    添加一个简单的[[NSRunLoop currentRunLoop] run]; 为我解决了这个问题

    【讨论】: