Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The Mute Button Won't Mute AVAudioPlayer

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

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.

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

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.

Any idea?

like image 857
Di Wu Avatar asked Feb 19 '12 03:02

Di Wu


2 Answers

From docs:

enter image description here

So basically you just have to figure out which Audio Session category suits your need.

like image 154
mfaani Avatar answered Oct 13 '22 06:10

mfaani


I realized it was because I had this line of code

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

I then changed it into

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

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

like image 41
Di Wu Avatar answered Oct 13 '22 07:10

Di Wu