Caleb Prenger
Caleb Prenger

Reputation: 2067

WebAudio API and cordova still play audio on exit

I'm using the howerjs audio library for my game that I am creating with Cordova. How can I disable the entire app or pause the audio when the user leaves the app? Right now the music continues to play. Is there a hook?

Upvotes: 0

Views: 216

Answers (1)

Philip Bijker
Philip Bijker

Reputation: 5115

You could attach a function to the pause event. This method is thrown by Cordova when the application moves to the background.

document.addEventListener("pause", onPause, false);

function onPause() {
    // audio.pause();
}

Upvotes: 1

Related Questions