6
A
回答
7
如果您仍想潛水和亂用這個魔淵,我能夠建立一些共同組成我發現這裏的代碼:
要註冊一個聽AudioProperties和捕獲有關'kAudioSessionProperty_AudioRouteChange'的任何消息。使用'理由'和'名字'可以解析收集發生的事情。您也可以閱讀更多有關在這裏:
// 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 function
AudioSessionAddPropertyListener (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
}
}
}
5
這是「那些事」一:事情你應該永遠,永遠需要做什麼或知道。一般的想法是,你使用提供的API來播放聲音,而聲音子系統負責其餘部分。
如果您需要特定配置,您可以通過對話框要求用戶以特定方式親切配置他的系統,但就是這樣。其原因是一般的驅動程序編程和特別是聲音編程構成了很深的魔法,任何試圖以任何理由試圖纏繞機器硬件的應用程序通常都會失敗,但通常很微妙。
除非您正在爲已知的封閉機器開發企業應用程序,否則不要對機器硬件做出假設:在您知道它之前,下一個型號的iMac不帶模擬插孔。
即使模擬插孔存在且爲空,也可以通過次要聲卡(板載,PCI或USB)發出聲音。哎呀,即使有內存服務,甚至還有FireWire聲卡在外面飄蕩。
-3
這是一個隱藏的功能,存在(或不)在您的嵌入式芯片上。 如果製造商發佈一個API,你可以控制它,否則你不能。
相關問題
- 1. iPhone中的插孔/耳機檢測
- 2. 如何檢測WinRT中未插入的耳機插孔?
- 3. 檢測耳機是否插入Java耳機插孔
- 4. Android的耳機插孔
- 5. 如何檢測UWP應用程序中未插入的耳機插孔?
- 6. 在Xamarin.iOS(iOS 7)中檢測耳機插孔上的插拔事件
- 7. 我如何檢測到有東西插入與vb.net的音頻插孔
- 8. 耳機插孔聽衆Android
- 9. 檢測硬件耳機機在Mac
- 10. 我如何檢測到有什麼東西插入到與Python的Linux上的音頻插孔?
- 11. 如何檢測在Android 8.0上插入耳機的targetSDKVersion> = 26
- 12. 操縱耳機插孔輸出
- 13. iPhone耳機插孔 - 讀入數據?
- 14. 如何在Android中檢測BT耳機或有線耳機
- 15. 閱讀iPhone耳機插孔或藍牙(心率測量)
- 16. Android:檢測耳機以及耳機?
- 17. 檢測耳機是否插入iPhone
- 18. 檢測耳機是否插入iPhone/iPod
- 19. 如何檢測耳機是否連接到Mac或斷開
- 20. JavaME:如何檢測耳機插件和插件?
- 21. 在Windows中檢測耳機
- 22. 如何檢測「離線」模式下的耳機插頭事件
- 23. 通過Android手機的耳機插孔發送數據
- 24. 在Mac OS X上使用AudioUnit檢測揚聲器/耳機
- 25. Swift:如何通過耳機插孔從固體按鈕輸入?
- 26. 檢測我在其上插入東西的表格
- 27. 在android耳機插孔中創建特定的方形信號
- 28. 如何在開始服務時檢測BT耳機/耳機
- 29. 如何檢查耳機是否插入?
- 30. 如何檢測耳機功能
你不能查詢MAC的揚聲器配置? – RedX 2011-05-05 09:23:49
那麼你會怎麼做呢? – David 2011-05-05 22:32:55