iOS8 AVAudioSession setActive error

后端 未结 5 1105
独厮守ぢ
独厮守ぢ 2020-12-28 12:00

I\'m testing my app in XCode 6 and find an issue with AVAudioSession in iOS8.

When I call

[[AVAudioSession sharedInstance] setActive:NO error

5条回答
  •  春和景丽
    2020-12-28 13:06

    I'm using AVAudioEngine and AVAudioPlayerNode to play sounds. I meet the same problem. My environment is iOS 10.

    I use AVAudioSession.sharedInstance() to handle AVAudioSession. When I run my app in simulator everything is fine, but when I switch it to my device. It failed.

    I suppose that I'm using the same session to handle recording and playing. So it may cause some strange issues. In my case, I record the sound and delay 1s to play it. So when I use stopRecordingAudio(), I add this piece of code :

    if audioEngine.running {
        audioEngine = AVAudioEngine() // var audioEngine = AVAudioEngine()
        try! AVAudioSession.sharedInstance().setActive(false)
    }
    

    After redefining audioEngine, audioEngine had been forced to stop and session was released. Crash is never happened again.

    Hope this message could help you.

提交回复
热议问题