Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AVFAudio`-[AVAudioSession setActive:withOptions:error:]: #40

Open
ChokShen opened this issue Mar 30, 2018 · 3 comments
Open

AVFAudio`-[AVAudioSession setActive:withOptions:error:]: #40

ChokShen opened this issue Mar 30, 2018 · 3 comments

Comments

@ChokShen
Copy link

ChokShen commented Mar 30, 2018

录音时偶现的bug,在stackoverflow找到了原因,应该是录音和播放使用的同一个AVAudioSession,导致崩溃。解决方法是在AudioPlayManager的stopPlayer()方法中加一句代码self.audioPlayer!.prepareToPlay()重置AVAudioSession:
func stopPlayer() {
if self.audioPlayer == nil {
return
}
self.audioPlayer!.delegate = nil
self.audioPlayer!.stop()
self.audioPlayer!.prepareToPlay() //必须加上这一句,否则有可能会出现AVFAudio`-[AVAudioSession setActive:withOptions:error:]:的bug
self.audioPlayer = nil
UIDevice.current.isProximityMonitoringEnabled = false
}

@hilen
Copy link
Owner

hilen commented Mar 30, 2018

赞,可以提交一个 PR

@ChokShen
Copy link
Author

ChokShen commented Apr 2, 2018 via email

@hilen
Copy link
Owner

hilen commented Apr 2, 2018

感谢感谢~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants