addEventListener not firing paues and resume - Resume HTML5 audio after receiving a Phone Call or Notification on Android

StackOverflow https://stackoverflow.com/questions/20697983

Pregunta

I am developing a PhoneGap / JQMobile app that plays Audios on Android Phone from an Internet source. For this I am using HTML5 .

When a phone call comes in or a notification beeps for SMS etc., the Audio stops playing and doesn't resume afterwards. My understanding is that I should use addEventListner for "pause" and "resume" (and please correct me if I am wrong) to implement auto-restart functionality. However the respective callback functions for these events are not fired when a notification/call arrives or finishes.

Here is the eventlistner code and callback functions:

document.addEventListener('deviceready', deviceReady(), false);

function deviceReady() {
    document.addEventListener("pause", AppPaused, false);
    document.addEventListener("resume", AppResumed, false);
}


function AppPaused()
{
    $(".message").text("Application Pause");
    alert("app paused");
    return;
}

function AppResumed()
{
    $(".message").text("Application Resumed");
    alert("app resumed");
    return;
}

Can someone please help me resolve this issue.

Thanks & Regards

AR

¿Fue útil?

Solución

Use this:

$(document).ready(function() {

   document.addEventListener("resume", AppResumed, false);
        function AppResumed() {
                   // Handle the resume event
                                   $(".message").text("Application Resumed");
                                   alert("app resumed");
                  }
});

Edited:

phonegap.js must be added and cordova js removed in order for this to work!

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top