如何以编程方式感知 iPhone 静音开关?

编程入门 行业动态 更新时间:2024-10-24 02:02:11
本文介绍了如何以编程方式感知 iPhone 静音开关?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我似乎无法在 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.事实上,您提供的链接会指向正确的答案(最终.;)为了完整性(因为 S.O. 应该是快速答案的来源!)...

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 静音开关?

本文发布于:2023-11-27 20:13:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639444.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:静音   方式   iPhone

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!