AVFoundation音频不停在静音
问题描述:
嘿家伙所以出于某种原因,当你静音手机的音频仍然来自应用程序。任何想法如何解决?AVFoundation音频不停在静音
private func myFunc() {
// Set up the audio session
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
try AVAudioSession.sharedInstance().setActive(true)
} catch {
fatalError("Unable to set the audio session because: \(error)")
}
guard
let audioURL = Bundle.main.url(forResource: "lololol", withExtension: "mp3"),
let player = try? AVAudioPlayer(contentsOf: audioURL)
else { fatalError("Unable to create player") }
if let aPlayer = audioPlayer {
if audioPlayer?.isPlaying == false {
audioPlayer = player
player.play()
}
} else {
audioPlayer = player
player.play()
}
}
答
我改变AVAudioSessionCategoryPlayback
到AVAudioSessionCategoryAmbient
解决它。