1

是否可以将音频输出到 iOS 设备的耳机插孔而不能输出到其他地方?(例如不是扬声器或蓝牙)

我们正在试验一个硬件插件,它从音频插孔接收输入作为音调。我们可以尝试检测耳机插孔是否已连接,但这仍然存在连接蓝牙音频输出设备的情况——我们不希望在用户的蓝牙耳机或扬声器中听到声音。

4

1 回答 1

6

You need read AudioSessionProgrammingGuide

You can get the current audio 'route' by calling AudioSessionGetProperty with the kAudioSessionProperty_AudioRoute property. This gives you a string such as "Headphone" or "Speaker" and play audio file receptively 'route' value

CFStringRef route;
UInt32 propertySize = sizeof(CFStringRef);
AudioSessionInitialize(NULL, NULL, NULL, NULL);
AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &propertySize, &route);

NSLog(@"%@ %@",route,kAudioSessionInputRoute_Headphone);
NSLog(@"%ld",CFStringGetLength(route));
if ([(__bridge NSString *)route isEqualToString:@"Headphone"])
{
    // play audio sound
}
else
{
     // not play audio sound
}

I hope it help you

于 2013-06-01T07:46:08.597 回答