CoreMediaIO,错误地更新了属性kCMIODevicePropertyDeviceIsRunningSomewhere [英] CoreMediaIO, incorrectly updated properties kCMIODevicePropertyDeviceIsRunningSomewhere

查看:66
本文介绍了CoreMediaIO,错误地更新了属性kCMIODevicePropertyDeviceIsRunningSomewhere的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

我也尝试使用CMIOObjectAddPropertyListenerBlock,但是他没有从我这里使用它.请告诉我,我做错了什么?我将非常感谢.

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

推荐答案

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

I also had the same problem. Getting data with CMIOObjectGetPropertyData worked but registering a listener block with CMIOObjectAddPropertyListenerBlock never received any event.

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

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.

请在此处查看: currentRunLoop

添加一个简单的 [[NSRunLoop currentRunLoop]运行]; 为我解决了此问题

Adding a simple [[NSRunLoop currentRunLoop] run]; fixed the issue for me

这篇关于CoreMediaIO,错误地更新了属性kCMIODevicePropertyDeviceIsRunningSomewhere的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆