I play several sounds, each of which smooths out the background sound. When everything is ready, I restore the background sound. It happens that every time one of the audio files is played, the background decreases (optional). When the last sound ends, background sound is restored (also desired). However, after about 5 seconds, it throws this error and again reduces the sound (not what I want, since all the sounds are complete).
ERROR: [0x19c9af310] AVAudioSession.mm:646: - [AVAudioSession setActive: withOptions: error:]: Deactivating an audio session that triggers I / O. All I / O operations must be stopped or paused before the audio session is deactivated.
As far as I know, I stop and delete all audio.
There is 1 post I found here:
iOS8 AVAudioSession setActive error
But the solution does not work for me. Here is my audio player class. If you can advise what could be, I would appreciate it.
import Foundation import AVFoundation private var _singleton:O_Audio? = O_Audio() private var _avAudioPlayers:Array<AVAudioPlayer> = [] //Manages dimming and resuming background audio class O_Audio:NSObject, AVAudioPlayerDelegate { class var SINGLETON:O_Audio { if(_singleton == nil) { _singleton = O_Audio() } return _singleton! } class func dimBackgroundAudio() { AVAudioSession.sharedInstance().setActive(true, error: nil) } class func restoreBackgroundAudio() { AVAudioSession.sharedInstance().setActive(false, error: nil) } class func playSound(path:String) { var sound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource(path, ofType: "m4a")!) var audioPlayer = AVAudioPlayer(contentsOfURL: sound, error: nil) _avAudioPlayers.append(audioPlayer) audioPlayer.delegate = O_Audio.SINGLETON audioPlayer.prepareToPlay() audioPlayer.play() } func audioPlayerDidFinishPlaying(player: AVAudioPlayer!, successfully flag: Bool) { //this was from the 1 stack post I found but these //two lines do not solve my problem player.stop() player.prepareToPlay() var index:Int! for i in 0..._avAudioPlayers.count - 1 { if(_avAudioPlayers[i] == player) { index = i break } } _avAudioPlayers.removeAtIndex(index) if(_avAudioPlayers.count == 0) { O_Audio.restoreBackgroundAudio() } } func audioPlayerDecodeErrorDidOccur(player: AVAudioPlayer!, error: NSError!) { println("error") } }
Important update
So, I found what, in my opinion, is a serious cause of the problem. Our application is built in Cordoba. Thus, we have many calls to Safari (browser). And this error occurs whenever we play a video (which plays through Safari). It seems that Safari somehow softens the sound and supports the input / output stream.