【问题标题】:OSX: Detecting if audio is being played through the speakers using Core AudioOSX:使用 Core Audio 检测是否正在通过扬声器播放音频
【发布时间】:2015-11-26 01:51:38
【问题描述】:

我正在学习如何构建 OSX 应用程序,我想知道是否有办法检查系统上的任何应用程序是否输出了一些音频?谢谢

【问题讨论】:

    标签: macos core-audio


    【解决方案1】:

    我认为这可以通过kAudioDevicePropertyDeviceIsRunningSomewhere 属性进行检查。

    来自标题文档:

    A UInt32 where 1 means that the AudioDevice is running in at least one process on the system and 0 means that it isn't running at all.

    伪代码:

    bool isRunningSomewhere(AudioDeviceID deviceId) {
        uint32 val;
        uint32 size = sizeof(val);
        AudioObjectPropertyAddress pa = { kAudioDevicePropertyDeviceIsRunningSomewhere, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster };
        AudioObjectGetPropertyData(deviceId, &pa, 0, NULL, &size, &val);
        return val == 1;
    }
    

    这应该告诉您设备是否正在使用(即有一个活动的IOProc。)但它不会告诉您IOProc 是否只是发送静音。

    【讨论】:

    • 非常感谢,我今晚试试,然后回复你。
    【解决方案2】:

    这不能在用户应用程序级别完成。可能通过安装 OS X kext(内核扩展)或自定义音频设备驱动程序来实现,这需要 sudo 权限并且可能需要重新启动。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多