xia*_*lin 41 avaudiosession xcode6 ios8
我在XCode 6中测试我的应用程序,并在iOS8中发现AVAudioSession的问题.
我打电话的时候
[[AVAudioSession sharedInstance] setActive:NO error:nil];
我收到以下错误消息:
AVAudioSession.mm:623: - [AVAudioSession setActive:withOptions:error:]:停用已运行I/O的音频会话.在停用音频会话之前,应停止或暂停所有I/O.
在AVAudioSession.h中,它说
请注意,如果会话在运行或暂停I/O(例如音频队列,播放器,录像机,转换器,远程I/O等)时设置为非活动状态,则此方法将在iOS 8上或之后链接的应用中引发异常. .
但我不知道如何检查是否有运行的I/O以及如何在需要重置音频会话时将其全部丢弃.
I solved this problem, inserting this code in the method of AVAudioPlayerDelegate.
-(void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag{
[audioPlayer stop];
[audioPlayer prepareToPlay];
}
Run Code Online (Sandbox Code Playgroud)
where audioPlayer is a variable declared in the header of my class.
the instruction prepareToPlay should resolve your problem!
| 归档时间: |
|
| 查看次数: |
18148 次 |
| 最近记录: |