AVAudioSession Audio Dimming Error: Deactivating an audio session with I / O triggering

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.

+4
source share
3 answers

The problem is that the MPMoviePlayerController object is playing. In fact, any AVPlayerItem causes this. If you play a movie and try to smooth out the sound, you will get this error.

Currently, any movie played on iOS has an unchangeable sound track (even if there is no sound in the video file). This constantly causes the duck problem (its error in the source code). I tried many workarounds and nothing worked. I am sure this is an Xcode source error.

+1
source

@Aggressor: you can change the audio category to a multiple route so that sound is played through the speaker and headphones (if connected) at the same time.

This way you will not get a darkened sound.

0
source

I have the same problem. You should call AVAudioSession.sharedInstance (). SetActive (true, error: nil); before setting AVAudioSession.sharedInstance (). setActive (false, error: nil);

And they appear in pairs.

0
source

All Articles