objective-c – 如何在Mac上检测耳机插孔中的某些东西?

objective-c – 如何在Mac上检测耳机插孔中的某些东西?,第1张

概述有没有办法检测是否有东西插入Mac的耳机插孔使用c或objective-c? 谢谢 你是否还想潜入并捣乱这种深刻的魔法,我能够根据我在这里找到的代码一起构建一些东西: http://www.iphonedevsdk.com/forum/iphone-sdk-development/54013-hardware-volume-change-listener-callback.html 您想要注册一个 有没有办法检测是否有东西插入Mac的耳机插孔使用c或objective-c?

谢谢

解决方法 你是否还想潜入并捣乱这种深刻的魔法,我能够根据我在这里找到的代码一起构建一些东西:

http://www.iphonedevsdk.com/forum/iphone-sdk-development/54013-hardware-volume-change-listener-callback.html

您想要注册一个ListenPropertIEs,并捕获有关’kAudioSessionProperty_AudioRouteChange’的任何消息.使用“原因”和“名称”,您可以解析发生的事情.您还可以在此处阅读更多相关信息:

http://developer.apple.com/library/ios/#DOCUMENTATION/AudioToolbox/Reference/AudioSessionServicesReference/Reference/reference.html

// Registers this class as the delegate of the audio session.[[AVAudioSession sharedInstance] setDelegate: self];// Use this code instead to allow the app sound to continue to play when the screen is locked.[[AVAudioSession sharedInstance] setcategory: AVAudioSessioncategoryPlayback error: nil];// Registers the audio route change Listener callback functionAudioSessionAddPropertyListener (kAudioSessionProperty_AudioRouteChange,audioRoutechangelistenerCallback,self);

回电话:

voID audioRoutechangelistenerCallback (voID *inUserData,AudioSessionPropertyID inPropertyID,UInt32 inPropertyValueSize,const voID *inPropertyValue ) {    // ensure that this callback was invoked for a route change    if (inPropertyID != kAudioSessionProperty_AudioRouteChange) return;    {        // Determines the reason for the route change,to ensure that it is not        //      because of a category change.        CFDictionaryRef routeChangeDictionary = (CFDictionaryRef)inPropertyValue;        CFNumberRef routeChangeReasonRef = (CFNumberRef)CFDictionaryGetValue (routeChangeDictionary,CFSTR (kAudioSession_AudioRouteChangeKey_Reason) );        SInt32 routeChangeReason;        CFNumberGetValue (routeChangeReasonRef,kcfNumberSInt32Type,&routeChangeReason);        if (routeChangeReason == kAudioSessionRouteChangeReason_oldDeviceUnavailable) {            //Handle headset Unplugged        } else if (routeChangeReason == kAudioSessionRouteChangeReason_NewDeviceAvailable) {                    //Handle headset plugged in        }    }}
总结

以上是内存溢出为你收集整理的objective-c – 如何在Mac上检测耳机插孔中的某些东西?全部内容,希望文章能够帮你解决objective-c – 如何在Mac上检测耳机插孔中的某些东西?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1035318.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-24
下一篇2022-05-24

发表评论

登录后才能评论

评论列表(0条)

    保存