iOS8 AVAudioSession setActive错误 [英] iOS8 AVAudioSession setActive error
问题描述
我在XCode 6中测试我的应用程序并在iOS8中发现了AVAudioSession的问题。
I'm testing my app in XCode 6 and find an issue with AVAudioSession in iOS8.
当我打电话时
[[AVAudioSession sharedInstance] setActive:NO error:nil];
[[AVAudioSession sharedInstance] setActive:NO error:nil];
我得到了以下错误消息:
I get the following error message:
AVAudioSession.mm:623: - [AVAudioSession setActive:withOptions:error:]:
停用音频已运行I / O的会话。在停用音频会话之前,所有I / O应该是
停止或暂停。
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中,它说
In AVAudioSession.h, it says
请注意,如果会话在运行或暂停时设置为非活动状态,此方法将在iOS 8上或之后链接的应用中引发异常I / O(例如音频队列,播放器,录像机,转换器,远程
I / O等)。
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以及如何在需要重置音频会话时处理所有内容。
But I'm not sure how can I check if there's running I/O and how can I dispose all when I need to reset the audio session.
推荐答案
我解决了这个问题,在AVAudioPlayerDelegate的方法中插入此代码。
I solved this problem, inserting this code in the method of AVAudioPlayerDelegate.
-(void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag{
[audioPlayer stop];
[audioPlayer prepareToPlay];
}
其中audioPlayer是我班级标题中声明的变量。
where audioPlayer is a variable declared in the header of my class.
指令prepareToPlay应解决您的问题!
the instruction prepareToPlay should resolve your problem!
这篇关于iOS8 AVAudioSession setActive错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!