Admiral-Billy / PokeRogue-App-Android

My PokeRogue app, but for Android, now open source!
MIT License
24 stars 4 forks source link

onPause and onResume don't seem to function properly, audio continues #3

Open tomatosoupcan opened 2 months ago

tomatosoupcan commented 2 months ago

Pretty easy to reproduce this, when you turn the screen off while in the app, or simply switch to another app without closing this first, the audio continues to play. I see that there is some effort being made to pause here, but it doesn't seem to function properly.

One option could be to load a blank page when the window is paused (i.e. .loadUrl("about:blank");) and then load back the main page. Although with Pokerogue this could be a bit frustrating, given the loading screen.

Afaik the only other option would be to execute JS against the game itself, and call one of the functions that pauses and resumes the BGM.

tomatosoupcan commented 2 months ago

After a bit of tooling around, seems like the lines would be something like

WebView.loadUrl("javascript:this.Phaser.Display.Canvas.CanvasPool.pool[1].parent.scene.pauseBgm()");

and

WebView.loadUrl("javascript:this.Phaser.Display.Canvas.CanvasPool.pool[1].parent.scene.resumeBgm()");

Admiral-Billy commented 2 months ago

Oh I see, I'll tool around with it some more to see if I can get it working. I tried some other attempts like muting the app when closed, but that had side effects like muting other audio streams so I just decided to stick with the imperfect solution.

tomatosoupcan commented 2 months ago

I've tested the above on a local build and it's been working great!