嘿伙计们出于某种原因,当你将手机静音时,音频仍然来自应用程序。关于如何解决的任何想法?
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()
}
}
答案 0 :(得分:1)
我通过将AVAudioSessionCategoryPlayback
更改为AVAudioSessionCategoryAmbient
来解决此问题。