如何检测 Mac 上耳机插孔中的内容?
有没有办法使用 c
或 objective-c
检测是否有东西插入 Mac 的耳机插孔?
谢谢
Is there a way to detect if something is plugged into the headphone jack of a Mac using c
or objective-c
?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是“那些事情”之一:你永远不应该、永远不需要做或知道的事情。总体思路是,您使用提供的 API 来播放声音,声音子系统负责其余的工作。
如果您需要特定的配置,您可以通过对话框要求用户以特定的方式配置他的系统,但仅此而已。
编辑:这样做的原因是,一般的驱动程序编程和特别的声音编程构成了深刻的魔力,任何试图以任何原因破坏机器硬件的应用程序通常都会失败,但通常会失败巧妙地。
除非您正在为一组已知的封闭机器开发企业应用程序,否则永远不要对机器硬件做出假设:在您意识到之前,下一代 iMac 型号根本没有模拟插孔。
即使模拟插孔存在并且是空的,声音也可以通过辅助声卡(板载、PCI 或 USB)进行引导。哎呀,如果没记错的话,甚至还有 FireWire 声卡。
This is one of "those things": Things you should never, ever need to do or know. The general idea is that you use the APIs provided for playing sounds, and the sound subsystem takes care of the rest.
If you need a specific configuration, you can ask the user via dialog box to kindly configure his system in a specific manner, but that's about it.
Edit: The reason for this is that driver programming in general and sound programming in particular constitutes deep magic, and any application that tries to wrangle the hardware of the machine for any reason usually fail spectacularly, but often quite subtly.
Unless you are developing enterprise apps for a known, closed set of machines, never make assumptions about machine hardware: before you know it, the next model of the iMac comes without an analog jack, like, at all.
And even if the analog jack is present and empty, sound could be directed via a secondary sound card, either on-board, PCI or USB. Heck, there is even FireWire sound cards floating around out there, if memory serves.
这是嵌入式芯片上存在(或不存在)的隐藏功能。
如果制造商发布了API,您就可以控制它,否则您就不能控制它。
This is a hidden function that exist (or not) on your embedded chip.
If the manufacture release an API you can control it, otherwise you can't.
如果您仍然想深入研究并弄乱这个深层魔法,我可以从我在这里找到的代码中构建一些东西:
http://www.iphonedevsdk.com/forum/iphone-sdk-development/54013-hardware-volume-change-listener-callback.html
您想要注册对 AudioProperties 的监听并捕获有关“kAudioSessionProperty_AudioRouteChange”的任何消息。使用“原因”和“名称”,您可以分析发生的事情。您还可以在这里阅读更多相关信息:
http://developer. apple.com/library/ios/#DOCUMENTATION/AudioToolbox/Reference/AudioSessionServicesReference/Reference/reference.html
回调:
Should you still want to dive in and mess with this deep magic I was able to construct something together form the code I found here:
http://www.iphonedevsdk.com/forum/iphone-sdk-development/54013-hardware-volume-change-listener-callback.html
You want to register a listen to the AudioProperties and catch any messages about 'kAudioSessionProperty_AudioRouteChange'. Using the 'reason' and the 'name' you can parse togather what happened. You can also read more about that here:
http://developer.apple.com/library/ios/#DOCUMENTATION/AudioToolbox/Reference/AudioSessionServicesReference/Reference/reference.html
Callback: