簡體   English   中英

AVFoundation音頻不會在靜音時停止

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM