I have problem with this notification when I play my game HTML5 made with construct 3 in android browser . When the game starts, the sounds play in the background even when I exit the browser. I tried this code :
//
GoToLayout(layout) {
if (this._runtime.IsLoading()) return;
const layoutManager = this._runtime.GetLayoutManager();
if (layoutManager.IsPendingChangeMainLayout()) return;
// Audio notification blocking script
(function() {
// Store the original AudioContext
const OriginalAudioContext = window.AudioContext || window.webkitAudioContext;
// Override AudioContext to add custom behavior
window.AudioContext = window.webkitAudioContext = function(...args) {
const audioContext = new OriginalAudioContext(...args);
// Override the close method
const originalClose = audioContext.close;
audioContext.close = function() {
originalClose.call(this);
// Additional cleanup to ensure no background audio
this.destination.disconnect();
};
// Add an event listener for visibility change
document.addEventListener('visibilitychange', function() {
if (document.hidden) {
audioContext.suspend();
} else {
audioContext.resume();
}
});
return audioContext;
};
// Attempt to disable notifications
if ('Notification' in window) {
Notification.requestPermission().then(function(permission) {
if (permission === 'granted') {
// Override the Notification constructor to block audio notifications
const OriginalNotification = window.Notification;
window.Notification = function(title, options) {
if (options && options.silent === undefined) {
options.silent = true;
}
return new OriginalNotification(title, options);
};
window.Notification.requestPermission = OriginalNotification.requestPermission;
}
});
}
})();
// Proceed with changing the layout
layoutManager.ChangeMainLayout(layout);
},
But it doesn’t work. I want a way to prevent this notification from appearing.
But it doesn’t work. I want a way to prevent this notification from appearing.