Hello community,
I have a Phaser game built for both iOS and android apps built using capacitor plugin and used capacitor app to check the app states.
The app state is recognising the change in app state such as foreground or backgrounded, but the music does not resume as intended only in iOS when the app comes to foreground. And it works fine in android build.
How the app is behaving in iOS?
- when I Open the phaser app on iOS device, the audio starts playing.
- If I Lock the device and unlock it or if I send the app to background and open it again,
- Game sound is still in paused state.
Below is information,
Phaser 3
@capacitor/app@6.0.1
below is code information of how I am handling app states,
App.addListener("appStateChange", (appState: AppState) => {
this.handleAppStateChange(appState);
});
handleAppStateChange(appState: AppState): void {
if(appState.isActive) {
this.audio.resume();
} else {
this.audio.pause();
}
}
and Also have the below listener in the code
App.addListener("pause", async () => {
this.audio.pause();
});
App.addListener("resume", () => {
this.audio.resume();
});
and nothing is changed in AppDelegate.swift
func applicationWillEnterForeground(_ application: UIApplication) {
}
but the audio is not resuming and facing issue in iOS app.
Tried adding below code
this.game.events.on(Phaser.Core.Events.VISIBLE, () => {
this.audio.resume();
})
but the issue is same.
Another thing tried is adding below to scene manager
audio: {
disableWebAudio:false,
}
when I alter the code of handleAppStateChange
method as below, it works only for iPhone 7 version. When I entered foreground for the phaser app, the sound will resume on iPhone 7 and below device.
handleAppStateChange(appState: AppState): void {
if(appState.isActive) {
this.audio.resume();
}
}
what could be the reason for the same?
So by analysing above information and code can anyone suggest what is correct way and kindly inform if I am doing anything wrong or how it could be improved.