Phonegap / Cordova pause event triggered by resume for android; can't mute the sound as a result

I am developing a Phonegap application that plays audio using the Phonegap Media plugin. When I press the home button or the screen lock button on my Android device (KitKat 4.4), the application goes in the background as it should, but the sound does not turn off because the pause event is not triggered. Only when I resume the application, is there a pause event, and my code, to turn off the sound, finally starts. The resume event also fires right after that.

Reading Phonegap documents on a pause event, there is a note about iOS Quirks:

"In the pause handler, any Cordova API calls or plugins that pass through Objective-C do not work with any interactive calls, such as warnings or console.log (). They are processed only when the application resumes in the next execution loop."

This is very similar to what I see on my Android device, although I am wondering if this is the same problem. I really need a fix or workaround, as it is showstopper so that there is no way to mute when the user pauses the application.

Here is my code to add a pause event listener:

document.addEventListener('deviceready', on_device_ready, false); function on_device_ready() { document.addEventListener('pause', on_pause, false); document.addEventListener('resume', on_resume, false); } 

UPDATE: I think I decided , although I am not too happy with the decision. I set the PhoneGap config.xml KeepRunning variable to false. I set true and now it gets a pause event when it is supposed to. I feel that I should be able to stop my application from running in the background, and also start some pause code in advance.

Anyway, here is the config.xml line I'm talking about:

 <preference name="KeepRunning" value="true"/> 
+8
javascript android cordova
source share

No one has answered this question yet.

See similar questions:

one
keepRunning set to false - what does it really do on Android?
one
(Android Cordova application) document.addEventListener ("pause", onPause, false); not called when the phone is locked or the home button is pressed)

or similar:

7
ion pause resume event prevent from fire by file view only fire when you press the home button
4
Is it possible to have access to the network after the pause event in the PhoneGap iOs application?
3
Cordoba only executes plugins after renewal event
3
Playing audio in the background (when the screen is off) Cord plugin
2
Pause Youtube video on Android Cordova sleep screen
2
Deviceready event does not fire when application restarts / resumes on android
one
Android Phonegap application does not resume
one
Cordoba resume application running in the background: Phonegap
0
How to pause audio when an Android application is paused - Edge Animate and PhoneGap Build
-one
Restarting Phonegap Android app instead of resuming

All Articles