[英]Objective-C: To mute/unmute audio while recording video using AVFoundation on iOS
[英]AVFoundation Audio not stopping on mute
大家好,由於某些原因,當您使手機靜音時,音頻仍然來自該應用程序。 有關如何解決的任何想法?
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
更改為AVAudioSessionCategoryPlayback
來解決此AVAudioSessionCategoryAmbient
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.