How to determine whether an Instant game is focused/unfocused via Android?
1

I need to essentially toggle audio (mute/unmute) for an fb instant game we're developing.

I've been using the "onPause()" function, which takes a callback that is then being called during each interruption (switching apps, home screen, screen lock etc). This is where I've imposed a toggleMute() function.

The results are great and seem to be working fine for iOS (as far as I know), however there's an issues when testing this on Android devices. A problem occurs whereby switching apps or heading to the home screen etc (general app interruption) for the first time, the onPause() is being called. Yet when returning back to the fb app/game, the onPause() fails to call (or is being ignored to some extent) thus skipping the toggleMute function and causing the whole audio system to stay muted until further interruption, which then unmutes and vice versa.

Is there a work-around for this issue? Bearing in mind that this recursively happens on both fb and the fb gaming app.

Here is a step by step to my problem:: 1. I define the callback FBInstant.onPause(() => { AudioSystem.toggleMuteAll(); });

  1. Audio plays on game load
  2. During app interruption, audio mutes. Great. 4 When returning back to game, audio stays muted.
  3. During another interruption, audio stays muted, until..
  4. Returning back to game yet again, audio plays.

And so on.

William
Asked about 2 months ago