本文介绍了静音按钮不会使AVAudioPlayer静音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I need to loop play a .caf file in my iPhone app.

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

The AVAudioPlayer looks promising. But there's one problem. It won't stop or mute even if I pressed the mute button on the iPhone.

我明白,没有办法以编程方式找出该静音按钮是在iOS 5中按下或不按。

And I understand that there would be no way to programmatically find out whether that mute button is pressed or not in iOS 5.

所以,我需要知道的可能是关于AVAudioPlayer或AVAudioSession的一些属性。

So, what I need to know might be some properties about AVAudioPlayer or AVAudioSession. Or, perhaps, I may need to consider other libraries to loop playing my .caf file.

任何想法?

推荐答案

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

I realized it was because I had this line of code

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

然后我将其更改为

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

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

Then the mute button would work and stop my AVAudioPlayer...

这篇关于静音按钮不会使AVAudioPlayer静音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-16 02:43