ios - 静音按钮不会使 AVAudioPlayer 静音

标签 ios iphone avaudioplayer avaudiosession

我需要在我的 iPhone 应用程序中循环播放 .caf 文件。

AVAudioPlayer 看起来很有前途。但是有一个问题。即使我按下 iPhone 上的静音按钮,它也不会停止或静音。

而且我知道在 iOS 5 中无法以编程方式查明是否按下了静音按钮。

所以,我需要知道的可能是关于 AVAudioPlayer 或 AVAudioSession 的一些属性。或者,我可能需要考虑其他库来循环播放我的 .caf 文件。

有什么想法吗?

最佳答案

我意识到是因为我有这行代码

[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: nil];

然后我把它改成了

[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryAmbient error: nil];

然后静音按钮会起作用并停止我的 AVAudioPlayer...

关于ios - 静音按钮不会使 AVAudioPlayer 静音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9346438/

相关文章:

ios - 如何使用 IBAction 清除 UITextField 中的文本?

iphone - 将应用上传到应用商店

iphone - 如何直接在 UIView 上设置 Image?

ios - 使用AVPlayer播放时如何将音频连接到蓝牙

android - 使用WSO2作为移动应用程序的API网关时,如何安全地处理comsumer-key和secret

iOS:应用扩展之间是否共享安全飞地?

ios - CGRect根据中心点定位

iphone - 清除 dequeueReusableCellWithIdentifier 单元格

iphone - 多任务处理 : Stop Background Audio at Specific Time

swift - AVAudioPlayer 不播放音频文件 - swift