2016-12-04 18 views
0

電話をミュートすると何らかの理由で聞こえることがあります。オーディオはまだアプリから届いています。どのように修正するための任意のアイデア?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() 
    } 


} 

答えて

1

私はAVAudioSessionCategoryAmbientAVAudioSessionCategoryPlaybackを変更することにより、それを解決します。

関連する問題