我似乎无法在SDK中找到如何以编程方式感知iPhone上的静音按钮/开关。当我的应用程序播放背景音乐时,它会正确响应音量按钮,而我没有任何代码可以遵循,但是,当我使用静音开关时,它只会继续播放。
I can't seem to find in the SDK how to programatically sense the mute button/switch on the iPhone. When my app plays background music, it responds properly to the volume button without me having any code to follow that but, when I use the mute switch, it just keeps playing away.
如何测试静音的位置?
(注意:我的程序有自己的静音开关,但我希望物理开关覆盖它。)
(NOTE: My program has its own mute switch, but I'd like the physical switch to override that.)
谢谢!
推荐答案谢谢,JPM。事实上,你提供的链接会得到正确的答案(最终。;)为了完整性(因为SO应该是QUICK答案的来源!)...
Thanks, JPM. Indeed, the link you provide leads to the correct answer (eventually. ;) For completeness (because S.O. should be a source of QUICK answers! )...
// "Ambient" makes it respect the mute switch // Must call this once to init session if (!gAudioSessionInited) { AudioSessionInterruptionListener inInterruptionListener = NULL; OSStatus error; if ((error = AudioSessionInitialize (NULL, NULL, inInterruptionListener, NULL))) { NSLog(@"*** Error *** error in AudioSessionInitialize: %d.", error); } else { gAudioSessionInited = YES; } } SInt32 ambient = kAudioSessionCategory_AmbientSound; if (AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, sizeof (ambient), &ambient)) { NSLog(@"*** Error *** could not set Session property to ambient."); }更多推荐
如何以编程方式感知iPhone静音开关?
发布评论