5
\$\begingroup\$

I have a game that plays sounds when some events occur.

Currently, I am using AVAudioPlayer for the purpose of playing the sound. But just the bare AVAudioPlayer has a noticeable lag time before the first playback and it stops music played by other apps.

Also, it stops the ongoing playback when a new playback is ordered. Surely, I could use a list of AVAudioPlayers for each of the effects, but that feels clunky.

Sound stops when other sound is played

I want something that will play effects mixed, one on top of another; and I want them to be played on top of background music, if there is any. I do not use any sorts of frameworks, like SpriteKit or Unity. So, how do I do this?

\$\endgroup\$

2 Answers 2

1
\$\begingroup\$

Settled to a queue of AVAudioPlayers for each sound effect.

Not pausing music achieved with this: https://stackoverflow.com/a/29027722

\$\endgroup\$
1
\$\begingroup\$

You have to change your AVAudioSession to Category rather than the default (Solo).

[[AVAudioSession sharedInstance]setCategory:AVAudioSessionCategoryAmbient error:nil]; should do the trick.

If this doesn't work for you, the AVAudioSession documentation has a lot of information on Audio Session Categories, Modes, etc.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .