检测耳机按钮点击 iPhone SDK [英] Detect headset button click on iPhone SDK
问题描述
有没有办法检测耳机的播放/暂停按钮点击?
Is there a way to detect the headset's play/pause button click?
我设法检测到音量按钮的点击:
I managed to detect the volume buttons clicks using:
AudioSessionAddPropertyListener( kAudioSessionProperty_CurrentHardwareOutputVolume , audioVolumeChangeListenerCallback, self );
但我找不到中心按钮的 AudioSessionProperty.这样做的方法是什么?
But I can't find an AudioSessionProperty for the center button. What's the way to do that?
推荐答案
从您的应用程序外部完成的所有操作都被视为远程事件".如果您双击 Home 按钮并在此处按播放/暂停,则相当于按耳机上的播放/暂停按钮(双击下一个相同,三击上一个相同).
Everything that's done from outside your app is considered a "Remote Event". If you double-tap the Home button and press Play/Pause there, it's the equivalent of pressing the play/pause button on the headset (Same for double tapping for next, and triple tapping for previous).
这里是 iOS 远程事件的事件处理.
就个人而言,我喜欢继承 MainWindow (UIWindow
) 并覆盖 sendEvent:
方法,这样我可以更直接地管理它:
Personally, I like subclassing the MainWindow (UIWindow
) and overriding the sendEvent:
method, so I can manage it more directly:
- (void)sendEvent:(UIEvent *)event
{
if (event.type == UIEventTypeRemoteControl)
{
// Do stuff here
}
else
{
// Not my problem.
[super sendEvent:event];
}
}
希望对您有所帮助,中央按钮事件的枚举是 UIEventSubtypeRemoteControlTogglePlayPause
.
Hope that helps, the enum for the event of the central button is UIEventSubtypeRemoteControlTogglePlayPause
.
这篇关于检测耳机按钮点击 iPhone SDK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!