确定哪个应用程序正在使用音频设备 [英] Determine which application is using audio device

查看:98
本文介绍了确定哪个应用程序正在使用音频设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在macOS中使用CoreAudio来确定是否正在使用特定的音频输入设备.我正在尝试查找有关该设备正在使用中的情况的更多信息,但仍在寻找有关如何执行此操作的任何信息.

1)是否可以找到当前正在使用特定音频输入设备的应用程序?

2)是否可以确定某个应用程序是否正在使用音频设备(输入或输出),并且该设备当前在该特定应用程序中处于静音状态?

谢谢

解决方案

如果应用程序通过 kAudioDevicePropertyHogMode 占用了设备(即对该设备具有独占访问权限),则的值与此属性相关联的pid_t 是触发进程的进程ID(如果未触发设备,则为-1.)

否则,至少对于输出设备,多个应用程序可以共享该设备,并且混合了各种音频流.在那种情况下,您能做的(我所知道的)最好的方法是检查 kAudioDevicePropertyDeviceIsRunningSomewhere ,它会告诉您设备是否正在使用中,而不是正在使用哪个进程./p>

对于问题2,静音是音频设备的属性,特别是 kAudioDevicePropertyMute .如果有任何应用程序将该属性设置为true,则该设备将被所有应用程序静音.

I'm currently using CoreAudio in macOS to determine if a specific audio input device is in use. I'm trying to find a little more information about what's going on with that device if it is in use, but struggling to find any information on how to do this.

1) Is it possible to find the application that is currently using a specific audio input device?

2) Is it possible to determine if an application is using an audio device (input or output) and has the device currently muted in that specific application?

Thanks

解决方案

If the application has hogged the device (i.e. has exclusive access to it) via kAudioDevicePropertyHogMode, then the value of the pid_t associated to that property is the process id of the hogging process (or -1 if the device isn't hogged.)

Otherwise, at least for output devices, multiple applications can share the device and the various audio streams are mixed. In that case the best you can do (that I know of) is to check kAudioDevicePropertyDeviceIsRunningSomewhere which will tell you if the device is in use, but not which process(es) is/are using it.

For question 2, mute is a property of the audio device, specifically kAudioDevicePropertyMute. If any application sets that property to true, then the device will be muted for all applications.

这篇关于确定哪个应用程序正在使用音频设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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