我正在 XCode 6 中测试我的应用程序,并发现 iOS8 中的 AVAudioSession 存在问题。
当我打电话时
[[AVAudioSession sharedInstance] setActive:NO error:nil];
我收到以下错误消息:
AVAudioSession.mm:623: -[AVAudioSession setActive:withOptions:error:]: Deactivating an audio session that has running I/O. All I/O should be stopped or paused prior to deactivating the audio session.
在 AVAudioSession.h 中,它说
Note that this method will throw an exception in apps linked on or after iOS 8 if the session is set inactive while it has running or paused I/O (e.g. audio queues, players, recorders, converters, remote I/Os, etc.).
但我不确定如何检查是否有正在运行的 I/O,以及当我需要重置 Audio Session 时如何处理所有 I/O。
最佳答案
我解决了这个问题,将此代码插入到 AVAudioPlayerDelegate 的方法中。
-(void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag{
[audioPlayer stop];
[audioPlayer prepareToPlay];
}
其中audioPlayer是在我的类的 header 中声明的变量。
指令prepareToPlay应该可以解决您的问题!
关于avaudiosession - iOS8 AVAudioSession setActive错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24114323/