AudioMix ANR issue

Hey guys,
I am also having this issue in which Google Play vitals report that my game has a stuck partial wake lock named ‘AudioMix’.

I have corrected one scenario that I identified and described on this Pull Request on cocos2d-x repository

@drelaptop, this metric from the vitals affects the game visibility on Google Play. The threshold is 0.1%.
Could you take a look later on the Pull Request and see if it makes sense. It was easily reproducible with my game and I believe it will with other games/applications as well.

I have been on holidays the last two weeks so I have been completely disconnected from this issue… and now it seems we have good news!!

@slackmoehrle, can anyone on the team confirm that the fix by @gibertoni is working properly?

Thanks guys! :slight_smile:

@fryderyk88
I have detected another scenario in which AudioMix wake lock would get stuck while the game was on background. Check if this is the case with your application.

So, if the Scene’s EventDispatcher is disabled and the game is minimized, the AudioMix gets stuck.
On my case, the EventDispatcher was being disabled on the transition from one scene to another, and only re-enabled after the transition completed.
If the game got minimized while the transition had not finished yet, the wake lock got stuck even though the sound was paused.

WOW! I must do some tests but my game disables EventDispatcher lots of times so maybe this is my case. Do you have any solution for that? :slight_smile:

I simply re-enabled the EventDispatcher when I process the didEnterBackground() event

Oh thanks! I will try it in our next update and will post the results here (maybe we will have data in october).

Again thanks @gibertoni for your help :slight_smile:

@drelaptop, I think I have found new info about this problem. I have been testing my game on an HTC One with Android 5.0.2. If I play a large sound file on loop mode (.ogg format played by UrlAudioPlayer) the next thing happens (100% reproducible):

  1. experimental::AudioEngine::pauseAll(); works fine during the first play of the file.
  2. After it enters the first loop, experimental::AudioEngine::pauseAll(); does not pause the looped audio!

I have debugged and UrlAudioPlayer::pause is called correctly on step 2, but somehow it cannot pause the music.

So the thing is, when my game calls AppDelegate::applicationDidEnterBackground() and I call experimental::AudioEngine::pauseAll();, if a sound is looped using UrlAudioPlayer, the sound keeps playing even when the game is on background (I have tested, It happens when using home button, turning off the screen or even getting a call). Maybe this is the ANR I have seen on the Google Play Console.

I have been lucky to found a device where I can reproduce the problem :slight_smile:

I have found a temporary workaround, instead of just calling experimental::AudioEngine::pauseAll();, if I use this code to pause, the sound is paused correctly:


experimental::AudioEngine::pauseAll();
experimental::AudioEngine::resumeAll();
experimental::AudioEngine::pauseAll();

I just let you know, maybe you can fix this in the future :slight_smile:

Thanks for all!