Limited concurrent sounds AVAudioPlayer

I am currently developing an application using PhoneGap, it has some visuals and plays sounds. I use the PhoneGap Media Plugin for Audio playback, this uses the AVAudioPlayer on iOS.


I do have very little experience on native iOS development.


I'm creating a kind of book application with slides.

I have one long MP3 which plays in the background. This contains the voice and is translated to several languages. This soundfile is pretty long, i encode it to MP3 to save space, and the device should be using Hardware decoding for this track.

The other sounds are language independent. Each slide has some sounds that play independent of user interaction, and some play when the user taps a specific sprite on the screen. The "sound effects" i.e. the language independent content is in a adpcm ima4 wav format, this is done to make it easier for the CPU to decode the audio.

On Android this all works well, and the player can decode and playback all my sounds without any problems.

On iOS however, I can only play about 2 sounds (varies) simultaenously, while I need atleast 3 or 4, maybe even 5 simultaenous sounds.

I began to debug my Application in Xcode and noticed the following error popping up, and the playback of other sounds becoming deactivated. This happens when more than 2 or 3 sounds were played simoultaenously:


Error: [0x36d179dc] AVAudioSession.mm:646: [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.


I have not been able to find out where the function call comes from as I don't have the source code for the AVAudioSession.


However this only happens when I run my application on my iPad 2 or iPhone 4S (haven't tested any other hardware), but does not occur when I run the application in the iOS Simulator.


Memory usage and CPU usage are both normal ie. in the green area, and it should be able to playback the other sounds from a resources perspective.

Why does this happen, why is my audio session deactivated?


I do pretty much use the PhoneGap Media class as is and haven't don any native programming for iOS in this project.


I can give away my Source code upon request.


Any suggestions or tips are highly appreciated.

Thanks in advance

Replies

This error indicates that something in your app is still using audio I/O at the time when the AVAudioSession setActive:NO is being called. It’s impossible to say which object without more information, but sometimes it’s the result of calling an asynchronous stop method on a player of some sort and not waiting for the notification that the player has stopped before deactivating the audio session. So, on slower devices you may get different behaviors? That's a guess. You'll need to debug your code and dig a little deeper.

It's probably worth noting that all devices that we currently supported, including the 4s and iPad 2, have only software decoders so your MP3 isn't using any hardware to decode.