Raul Gonzalez
Raul Gonzalez

Reputation: 875

Muting AVFoundation sounds with physical mute iPhone button

I have added sounds to my game using AVFoundation and it works perfectly, except that in both setting mute ON and OFF (using physical mute button of the iPhone) the sounds play. How can I make my app to mute the sounds when the Mute Button is ON? this is the code I am using:

import AVFoundation

var audioPlayerMenu = AVAudioPlayer()
var selectSound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("select", ofType: "mp3")!)

audioPlayerMenu = AVAudioPlayer(contentsOfURL: selectSound, error: nil)
audioPlayerMenu.prepareToPlay()
audioPlayerMenu.play()

Upvotes: 2

Views: 614

Answers (1)

Emanuel Gonzalez
Emanuel Gonzalez

Reputation: 101

You can't do that using AVFoundation, I suggest allowing the user to choose inside your application to mute the sounds. Thats how almost every app I;ve seen they do it

Upvotes: 2

Related Questions