There is an issue with background music (BGM) not resuming correctly after closing advertisements in a Phaser 3 game embedded in a webview. When the app goes to the background, the BGM pauses as expected. However, when the app returns to the foreground and an advertisement (with sound) has been shown, the BGM does not resume after closing the advertisement.
Steps to Reproduce
Start the Phaser 3 game with looping background music (BGM).
Switch the app to the background, which pauses the BGM.
Return to the app, triggering an advertisement with sound to play.
Close the advertisement.
Observe that the BGM does not resume.
Expected Behavior
The BGM should resume playing after the advertisement is closed and the app returns to the foreground.
Actual Behavior
The BGM remains paused and does not resume after the advertisement is closed and the app is back in the foreground.
Additional Information
Phaser Version: [e.g., 3.55.2]
Browser: [e.g., Chrome 91, WebView]
Operating System: [e.g., Android 11, iOS 14]
Audio Context Status: The audio context is resumed correctly when the app returns to the foreground, but the BGM does not play.
function onAdEnded(callback) {
const adAudio = document.getElementById('adAudio');
if (adAudio) {
adAudio.addEventListener('ended', callback, { once: true });
}
}
This issue seems to be related to the interaction between the audio contexts of the advertisement and the Phaser game. Any guidance or fixes would be greatly appreciated.
Thank you!
Description
There is an issue with background music (BGM) not resuming correctly after closing advertisements in a Phaser 3 game embedded in a webview. When the app goes to the background, the BGM pauses as expected. However, when the app returns to the foreground and an advertisement (with sound) has been shown, the BGM does not resume after closing the advertisement.
Steps to Reproduce
Expected Behavior
The BGM should resume playing after the advertisement is closed and the app returns to the foreground.
Actual Behavior
The BGM remains paused and does not resume after the advertisement is closed and the app is back in the foreground.
Additional Information
function handleVisibilityChange(context) { if (document.hidden) { context.bgm.pause(); } else { if (!isAdPlaying()) { context.bgm.resume(); } else { onAdEnded(() => { context.bgm.resume(); }); } } }
function isAdPlaying() { const adAudio = document.getElementById('adAudio'); return adAudio && !adAudio.paused; }
function onAdEnded(callback) { const adAudio = document.getElementById('adAudio'); if (adAudio) { adAudio.addEventListener('ended', callback, { once: true }); } }