Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
150 views
in Technique[技术] by (71.8m points)

iOS8 AVAudioSession setActive error

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

When I call

[[AVAudioSession sharedInstance] setActive:NO error:nil];

I get the following error message:

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.

In AVAudioSession.h, it says

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.).

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.

question from:https://stackoverflow.com/questions/24114323/ios8-avaudiosession-setactive-error

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I solved this problem, inserting this code in the method of AVAudioPlayerDelegate.

-(void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag{
  [audioPlayer stop];
  [audioPlayer prepareToPlay];
}

where audioPlayer is a variable declared in the header of my class.

the instruction prepareToPlay should resolve your problem!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...