0
Q
如何確定錄音源
A
回答
0
確定此方法的方法是輪詢硬件並查詢當前的音頻路由。使用AudioSessionGetProperty對象獲取音頻路徑。
這example by @TPoschel應該讓你在正確的軌道上。
- (void)playSound:(id) sender
{
if(player){
CFStringRef route;
UInt32 propertySize = sizeof(CFStringRef);
AudioSessionInitialize(NULL, NULL, NULL, NULL);
AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &propertySize, &route);
if((route == NULL) || (CFStringGetLength(route) == 0)){
// Silent Mode
NSLog(@"AudioRoute: SILENT");
} else {
NSString* routeStr = (NSString*)route;
NSLog(@"AudioRoute: %@", routeStr);
/* Known values of route:
* "Headset"
* "Headphone"
* "Speaker"
* "SpeakerAndMicrophone"
* "HeadphonesAndMicrophone"
* "HeadsetInOut"
* "ReceiverAndMicrophone"
* "Lineout"
*/
NSRange headphoneRange = [routeStr rangeOfString : @"Headphone"];
NSRange headsetRange = [routeStr rangeOfString : @"Headset"];
NSRange receiverRange = [routeStr rangeOfString : @"Receiver"];
NSRange speakerRange = [routeStr rangeOfString : @"Speaker"];
NSRange lineoutRange = [routeStr rangeOfString : @"Lineout"];
if (headphoneRange.location != NSNotFound) {
// Don't change the route if the headphone is plugged in.
} else if(headsetRange.location != NSNotFound) {
// Don't change the route if the headset is plugged in.
} else if (receiverRange.location != NSNotFound) {
// Change to play on the speaker
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride);
} else if (speakerRange.location != NSNotFound) {
// Don't change the route if the speaker is currently playing.
} else if (lineoutRange.location != NSNotFound) {
// Don't change the route if the lineout is plugged in.
} else {
NSLog(@"Unknown audio route.");
}
}
[player play];
}
}
相關問題
- 1. 確定錄音的長度?
- 2. 如何確定JNDI資源
- 3. 如何獲取FM音頻流記錄的音頻源?
- 4. 如何確定iphone輸入錄製語音的頻率?
- 5. 如何確定錄製的音頻文件的大小
- 6. 給定音頻來源的任何語言的時間戳音頻和準確的轉錄
- 7. 如何確定gradle中的源目錄優先級?
- 8. 按輸入音量確定的時間進行錄音
- 9. 如何在Unity3D中靜音特定的音頻源?
- 10. 如何確定導入的來源?
- 11. 如何確定主,起源,頭
- 12. 如何確定QAction的來源?
- 13. wxPython:如何確定事件源
- 14. 如何確定CGPath的來源?
- 15. 如何確定KeyError的來源?
- 16. 如何確定LocalJumpError的來源?
- 17. 如何確定ActionListener中的事件源?
- 18. Android。如何做大音量錄音?
- 19. 如何錄製iphone音箱的音頻?
- 20. 如何源目錄
- 21. 如何確定音軌是否是杜比定向邏輯II混音
- 22. 確定播放過程中音頻的來源
- 23. 如何創建錄音WebApp?
- 24. 如何錄製音頻?
- 25. 如何繼續錄音?
- 26. 如何確定擴展的目錄
- 27. ASP.NET:如何確定帳戶登錄?
- 28. 如何確定登錄用戶角色
- 29. Symfony2 + Doctrine2:如何正確定位記錄?
- 30. 確定事件源