The Mute Button Won't Mute AVAudioPlayer

≡放荡痞女 提交于 2019-12-03 02:46:48

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...

my 2 cents for swift 3.0:

let sharedSession = AVAudioSession.sharedInstance()

do {
    try sharedSession.setCategory(AVAudioSessionCategoryAmbient)
} catch _{
    return false
}

or simpler:

try? sharedSession.setCategory(AVAudioSessionCategoryAmbient)

From docs:

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!