[SOLVED] AudioEngine bug on IOS after receiveing phone call

Hi,
Recently I upgraded to newer AudioEngine from SimpleAudioEngine in hopes of fixing the audio issues. Most are fixed however on IPhone, if I receive a call while game is in progress and then go ahead to play the game then Audio doesnt play anymore.

I am getting the following error when I try to play audio after resuming the game.

V/AudioPlayer (147): AudioPlayer::play2d, _alSource: 2400
E/AudioPlayer (161): OpenAL error 0xA003 in /Users/UserName/Desktop/GameNameV1.4/GameName/cocos2d/cocos/audio/apple/AudioPlayer.mm play2d 161

E/AudioPlayer (162): OpenAL error 0xA003 in /Users/UserName/Desktop/GameNameV1.4/GameName/cocos2d/cocos/audio/apple/AudioPlayer.mm play2d 162

E/AudioPlayer (163): OpenAL error 0xA003 in /Users/UserName/Desktop/GameNameV1.4/GameName/cocos2d/cocos/audio/apple/AudioPlayer.mm play2d 163

E/AudioPlayer (164): OpenAL error 0xA003 in /Users/UserName/Desktop/GameNameV1.4/GameName/cocos2d/cocos/audio/apple/AudioPlayer.mm play2d 164

E/AudioPlayer (202): OpenAL error 0xA003 in /Users/UserName/Desktop/GameNameV1.4/GameName/cocos2d/cocos/audio/apple/AudioPlayer.mm play2d 202

E/AudioPlayer (217): bool cocos2d::experimental::AudioPlayer::play2d():alSourcePlay error code:a003
V/AudioPlayer (69): ~AudioPlayer() (0x101e4de50), id=15
V/AudioPlayer (83): AudioPlayer::destroy begin, id=15
V/AudioPlayer (310): Exit rotate buffer thread ...
V/AudioPlayer (123): rotateBufferThread exited!
V/AudioPlayer (128): Before alSourceStop
E/AudioPlayer (129): OpenAL error 0xA003 in /Users/UserName/Desktop/GameNameV1.4/GameName/cocos2d/cocos/audio/apple/AudioPlayer.mm destroy 129

V/AudioPlayer (130): Before alSourcei
E/AudioPlayer (131): OpenAL error 0xA003 in /Users/UserName/Desktop/GameNameV1.4/GameName/cocos2d/cocos/audio/apple/AudioPlayer.mm destroy 131

V/AudioPlayer (136): AudioPlayer::destroy end, id=15

I did refer this link https://github.com/cocos2d/cocos2d-x/issues/17395
but it did not work. I am also facing the same issue that is mentioned in the above link.

Thanks

I solved this issue by following 2 steps.

  1. Get latest update of cocos2d x 3.16v
    After updating this, I tried to simulate the issue again and noticed some progress. Although background sound didnt play once game resumed after a phone call, other sound effects were working.

  2. Add delay while playing the background audio when game resumes.
    Previously, I would play background music immediately when game resumes. I thought of adding a little delay to it since sound effects that were played later would work. Hence instead of playing background audio immediately when game resumes, I added a delay of 0.25f seconds

If anyone encounters such issue, following above steps will solve it.

I can’t speak for iOS, but in Android there is something call Audio Focus. You can read more about it on medium.

In short: You have to request audio focus and after you get it, you should play music. This could be the issue with you artificial delay, because iOS doesn’t give your game the audio focus (or the corresponding term in the iOS world).

2 Likes

Thanks for the extra info. It gives me better understanding of how audio is handled.