Reputation: 1965
I am new in playing audio sound. I am stuck in problem where I wanted to mute other application sound when my application is playing music sound and resume back when I stop my application's sound. I searched a lot but I could not get any solution.
Below code is for playing audio sound:-
var url:NSURL = NSURL.fileURLWithPath(NSBundle.mainBundle().pathForResource("\(soundFile)", ofType: "mp3")!)!
let audioPlayer1 = AVAudioPlayer(contentsOfURL: url, error: nil)
audioPlayer1!.numberOfLoops = -1
if(audioPlayer1 == nil)
{
println("error in playing")
}
else
{
audioPlayer1!.play()
}
Upvotes: 1
Views: 2910
Reputation: 6612
You need to configure the AVAudioSession category :
AVAudioSession Class Reference : http://goo.gl/rh7CX7 . Look for which fit the most for your application. You only need to set it once in your code (make sure it's called).
AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategorySoloAmbient, error: nil) // AVAudioSessionCategorySoloAmbient is default
AVAudioSession.sharedInstance().setActive(true, error: nil)
If it didn't help, please provide more information (which app isn't mute ? what have you tried ? ...).
Upvotes: 1