iOS 9以静音模式播放音频,但保持其他应用程序的音乐播放运行

iOS 9以静音模式播放音频,但保持其他应用程序的音乐播放运行,第1张

概述我的应用程序中有一些警告声但我真的需要背景音乐(例如Spotify)才能继续在后台运行.我解决了这个问题 [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:nil]; 但是,在静音模式下,我的AVAudioPlayers静音但声音很重要,即使在静音模式下也是如此.我读到有关AudioSe 我的应用程序中有一些警告声但我真的需要背景音乐(例如Spotify)才能继续在后台运行.我解决了这个问题

[[AVAudioSession sharedInstance] setcategory:AVAudioSessioncategoryAmbIEnt error:nil];

但是,在静音模式下,我的AVAudioPlayers静音但声音很重要,即使在静音模式下也是如此.我读到有关AudioServicesPlaySystemSound忽略静默模式但它没有,至少在iOS9上没有.

还有其他可能吗?哦,请浪费你的时间说“我会讨厌这个用户”,“不称它为静音模式”,……这是一个编程页面,而不是哲学类.

解决方法 音频会话类别AVAudioSessioncategoryAmbIEnt将遵循文档中所述的Ring / Silent开关 –

AVAudioSessioncategoryAmbIEnt
The category for an app in which sound playback is nonprimary—that is,your app can be used successfully with the sound turned off…

… Your audio is silenced by screen locking and by the Silent switch (called the Ring/Silent switch on iPhone).

我建议尝试一个更合适的类别与混合选项,如 –

[[AVAudioSession sharedInstance] setcategory:AVAudioSessioncategoryPlayback                                  withOptions:AVAudioSessioncategoryOptionMixWithOthers                                        error:nil];

AVAudioSessioncategoryPlayback类别将忽略文档中提到的静默开关 –

When using this category,your app audio continues with the Silent switch set to silent or when the screen locks.

总结

以上是内存溢出为你收集整理的iOS 9以静音模式播放音频,但保持其他应用程序的音乐播放运行全部内容,希望文章能够帮你解决iOS 9以静音模式播放音频,但保持其他应用程序的音乐播放运行所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1072810.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存