[Cocos2d-x 3.4 BUG] AudioEngine 3.4 Freeze + incoming call

Hello everyone!

I was working with cocos2d-x 3.4 (xCode 6.2, iOS 8.2) today when I received a call on my iPad. I declined it, and when the cocos game came back there was no sound at all.

I’m using the new AudioEngine from 3.4.

I tested on the cpp-tests as well, and If I call and close the call on the iPad, when the game pops back there is no sound at all.

The only workaround I was able to use was to call AudioEngine::end(); in - (void)applicationWillResignActive:(UIApplication *)application

but this causes other problems.

  • Is this a bug in 3.4? If so, is this known?
  • Can you guys reproduce it?
  • How can I fix this?

Thank you in advance,

Davide

I have the same problem. Looks like a critical issue to me :confused:

I just verified that this is also the case on iOS in Cocos v3.3, when the new AudioEngine was introduced. Can someone test if this is also an issue on Android?

In quickly searching the source code for AudioEngine, it looks like it does not handle system level interruptions at all (nor a way to set session type, but that is a different issue). I found this page on interruption handling and briefly tried to add the interruption handling to audio/apple/AudioEngine-inl.h & .mm but was unable to make it restart the audio.

Maybe the Cocos team can fix it.

Hi there!
I found this issue on github: https://github.com/cocos2d/cocos2d-x/pull/10467

It looks like they already know about the issue, and they are going to fix in in 4.0.
However, I tested with their proposed fix and the problem is still there.

A little recap:

  • cocos2dx 3.4 with their fix
  • receving a call on iPhone is fine
  • receving and not answering a call on iPad is NOT FINE (audio does not start again)

Can you reproduce the issue as well?

Davide Jones

I did not test their fix per say, but on further investigation, it looks like it might be related to the default audio session category not handling the end from interrupt properly. I found that if I add this to AudioEngineImpl::init() it returns properly:

UInt32 session_category = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(session_category), &session_category);

I tried some of the other categories, and only this and kAudioSessionCategory_PlayAndRecord restarted the audio properly.

I agree that this is a critical issue and should be fixed sooner that 4.0.

1 Like

Thank you for you suggestion, I’m going to try that today!

It looks like it works with your fix!

To recap:

  • xCode 6.2, iOS 7/8, cocos2dx-3.4, iPhone/iPad alike
  • test-cpp with new audio engine does not play sound when coming back from siri/incoming call
  • github fix fixes the siri problem
  • this page fix fixes the incoming call problem for iPad

The only difference is that now it seems that if you manually ‘mute’ the device with the hardware button, the audio still plays, and you have to turn down the volume if you want to really mute it.

Waiting for new cocos2dx release to see how things will work. For the time being it looks like everything is fine.

1 Like

That is correct about using _MediaPlayback and the mute button, that is the way Apple intended that to work.