When starting, the sound start, when minimized don't stop. How can I do? Through
document.addEventListener("pause", onPause, false);
document.addEventListener("resume", onResume, false);
could not. Pause Event Listener could not do. Help. Sorry for bad English.
var app = {
initialize: function () {
this.bindEvents();
},
bindEvents: function () {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
onDeviceReady: function () {
app.receivedEvent('deviceready');
var myMedia = new Media("/android_asset/www/audio/sample.mp3")
myMedia.play({
playAudioWhenScreenIsLocked: false
});
},
receivedEvent: function () {
}
};
app.initialize();
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *; img-src 'self' data: content:;">
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
<title>SOOOUND!</title>
</head>
<body>
SOOOUND!
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
</body>
</html>
You'll have to add a Pause Event Listener to your application to listen for whenever it goes into the background.
document.addEventListener("onDeviceReady", function() {
// Adds pause event
document.addEventListener("pause", manageAppPause);
// Adds resume event
document.addEventListener("resume", manageAppResume);
});
function manageAppPause() {
// Check if audio is playing
// If it is, pause it
}
function manageAppResume() {
// If you want, check if the audio was playing before the app was put into background
// If so, resume audio
}
var app = {
initialize: function () {
this.bindEvents();
},
bindEvents: function () {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
onDeviceReady: function () {
var myMedia = new Media("/android_asset/www/audio/sample.mp3")
myMedia.play({
playAudioWhenScreenIsLocked: false
});
document.addEventListener('pause', onPause, false);
document.addEventListener('resume', onResume, false);
function onPause() {
myMedia.pause();
};
function onResume() {
myMedia.play();
};
},
};
app.initialize();
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *; img-src 'self' data: content:;">
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<title>SOOOUND!</title>
</head>
<body>
SOOOUND!
</body>
</html>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With