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. 如何确定iphone输入录制语音的频率?
- 3. 如何确定gradle中的源目录优先级?
- 4. 按输入音量确定的时间进行录音
- 5. 如何确定LocalJumpError的来源?
- 6. 如何确定CGPath的来源?
- 7. 如何确定主,起源,头
- 8. 如何确定QAction的来源?
- 9. 如何确定KeyError的来源?
- 10. wxPython:如何确定事件源
- 11. 如何录制iphone音箱的音频?
- 12. Android。如何做大音量录音?
- 13. 如何源目录
- 14. 如何确定音轨是否是杜比定向逻辑II混音
- 15. 如何继续录音?
- 16. 如何确定扩展的目录
- 17. 如何确定登录用户角色
- 18. ASP.NET:如何确定帐户登录?
- 19. 确定事件源
- 20. 无法确定从辅音
- 21. 使用音频工具sox,如何确定立体声录音是否实际上是单声道?
- 22. 如何设置录音限制通过使用录音机类?
- 23. 如何确定源代码的正确Visual Studio版本?
- 24. 如何确定是否在每个源记录,代表同一个人
- 25. 如何获取通过音频录音机录制的声音的幅度
- 26. 如何从资源播放音频
- 27. 如何混合PCM音频源(Java)?
- 28. 如何将音频流入OpenAL源?
- 29. 如何编写DirectX音频推送源
- 30. 如何确定指定方法的起源类?