Software Archive
Read-only legacy content
17061 Discussions

Don't know where else to go for Cordova browser audio help

Jeffrey_W_
Beginner
312 Views

I have been struggling with this issue for the last few weeks, and I have searched and asked everywhere I know to search and ask, so please forgive me if this isn't the place for this. But I always get the best help here.

I am using Google Play Games Achievements and Leaderboards in my Construct 2 game for Android. All audio (music/sounds) play fine if the user is logged in/out or if he logs IN to Google Play Games.

My problem is: If the user is logged in and he touches the Achievements or Leaderboards icons, ALL audio (music/sounds) are suspended, paused, muted or stopped (not exactly sure of which) when either the Achievements or Leaderboards are displayed.

And when the user backs out of those screens by using either the back button on their phone or on the screens of the Achievements or Leaderboards, the audio (music/sounds) NEVER resumes.

I've tried every different way that I know to get it to play again after the browser (game) is resumed.

Including:

Browser on resumed

Browser page is visible

Browser is full screen (the Google Play Games achievements/leaderboard forces the status bar to show).

Nothing seems to get the audio (music/sounds) to play again, not until the game is exited and restarted. 

 

If anyone can provide any kind of help with this, I would be immensely grateful. This is the only thing that I have left before publishing my game on the Play Store. 

 

0 Kudos
4 Replies
PaulF_IntelCorp
Employee
312 Views

Have you built the app for debug and use remote CDT to monitor the console for some possible clues? This will require some debugging with CDT to really understand what is going on. I suggest adding some console.log() messages to key event handlers in your code to monitor what is going on. See this doc page for help with remote CDT > https://software.intel.com/en-us/xdk/docs/using-remote-chrome-devtools-to-debug-android-cordova-apps <

0 Kudos
Jeffrey_W_
Beginner
312 Views

First, thank you for the reply.

Second, Wow Paul F you're giving me a lot of credit there. No clue what you just said, but will investigate.

I did learn this: the Android browser gets suspended when it goes into the background. There have been numerous posts (although most are older) about the audio either still playing on browser suspended ( i wish i had that problem) or not playing on resume. 

And that's my issue. I believe, after further reading, the android app is SUPPOSED to get suspended when it goes into the background, either from opening an external webpage, or from a user hitting their phones search button,  or from a google games leaderboard showing. 

But there doesn't seem to be much help on how to resume the audio when the browser comes back to the foreground. I will look into debugging with the remote CDT as you mentioned. And maybe, learn something along the way.

0 Kudos
Jeffrey_W_
Beginner
312 Views

Paul F

I have been reading up on pausing/resuming an apps state and I seen this: 

https://developer.android.com/guide/components/activities/activity-lifecycle.html

onPause()

onResume()

 

But I'm not experienced enough to know how or where I could put this in the additions.xml file. Or if it would even work.

Basically all I'm trying to do is: when the user calls the Leaderboard or Achievements, pause "Main_Music" and when either one of those two (Leaderboard or Achievements) are dismissed, resume "Main_Music".

The one major problem may be that not only does  "Main_Music" stop, all other music (Gameplay_Music) and soundfx stop also.

 

Still confused about how to resume all audio when the app is resumed/in focus, but learning something new.

 

0 Kudos
PaulF_IntelCorp
Employee
312 Views

Jeffrey -- yes, your app should pause when focus goes to a new app or activity, this is done, obviously, to insure a long battery life for your customer's mobile device.

Regarding the onPause() and onResume() functions, these are functions you create in response to the Cordova "pause" and "resume" functions. For example:

document.addEventListener("deviceready", function () {
    document.addEventListener("pause", onPause, false) ;
    document.addEventListener("resume", onResume, false) ;
}, false) ;

function onPause() {
    // save app state, etc. so you can resume your app
}

function onResume() {
    // restore app state, etc. so you can smoothly resume
}

This is just a simple template, to give you the idea. Note, there is no onPause() and onResume() function being used here, just two anonymous functions.

0 Kudos
Reply