如何检测耳机是否连接到iPod touch G1?

如何检测耳机是否连接到iPod touch G1?

问题描述:

有很多关于如何通过 AudioSessionGetProperty / kAudioSessionProperty_AudioInputAvailable 检测麦克风是否连接到iPod touch G2的文章,但我还没有看到任何与检测有关的文章连接到iPod touch G1的耳机。

There are many articles on how to detect if a microphone is connected to an iPod touch G2 via AudioSessionGetProperty / kAudioSessionProperty_AudioInputAvailable, but I have not seen any articles related to detection of headphones connected to an iPod touch G1.

要查看:
iPod touch G2硬件在以下方面与iPod touch G1硬件不同:

To review: iPod touch G2 hardware differs from iPod touch G1 hardware in the following ways:


  • iPod touch G2内置扬声器

  • iPod touch G2可以使用麦克风关闭耳机端口

我有一个应用程序,需要播放声音才有用,我想要很好,并有一个探测器,显示该应用程序是有用的一旦他们连接了一些耳机。

I have an app that needs to play sound to be useful and I want to be nice and have a detector that shows that the app is useful once they connect up some headphones.

我的初步试验显示AudioSession API(特别是 AudioSessionGetProperty kAudioSessionProperty_AudioRoute 强>不变)总是报告'耳机',即使他adphones未连接到iPod touch G1。

My initial trials show that the AudioSession APIs (and specifically the AudioSessionGetProperty with the kAudioSessionProperty_AudioRoute constant) always reports back 'Headphone' even if headphones are not connected to an iPod touch G1.

我错过了什么?我的AudioSession呼叫是否有交叉连线?如果有人在iPod touch G1上试过这个并获得了不同的结果?是否有另一种方法来编织AudioSession API并得到我想要的东西?

Am I missing something? Do I have something cross wired with my AudioSession calls? If anyone has tried this on an iPod touch G1 and got a different result? Is there another way to weave through AudioSession APIs and get what I am after?

这是针对真正iPod touch G1硬件上的iPhone OS 3.0和iPhone OS 3.0 SDK 。

This is all against iPhone OS 3.0 and the iPhone OS 3.0 SDK on real iPod touch G1 hardware.

提前致谢,
--Batgar

Thanks in advance, --Batgar

你可以很容易地使用这种方法:

you can easily get with this method:

- (BOOL)isHeadsetPluggedIn {
UInt32 routeSize = sizeof (CFStringRef);
CFStringRef route;

OSStatus error = AudioSessionGetProperty (kAudioSessionProperty_AudioRoute,
&routeSize,
&route);

if (!error && (route != NULL) && ([route isEqual:@"HeadsetInOut"])) {
return YES;
}

return NO;
}