How to stop sound playing in background (in a Webview or mobile browser)?

I have a sound playing in loop in my animation.
This animation is embeded in a webview (ios and android).
The pb is when I change the focus (return on homescreen, even switch-off the screen), the music continues to play…

A have to quit the app to stop sound (luckily)…

Same issue when I play the animation in the browser (chrome for android / safari for iphone), so I don’t think it’s a pure webview pb…

Any idea ?
Thanks a lot.

There is a thread existing on this.
Have a check through it and see if it helps…

Also note that for IOS at least it is recomended to use wkwebview.


Thanks, no I didn’t found that topic in my investigations…

Of course I use wkwebview, I said “webview” to speak in general.
I’m going to read that and tell you if it’s works for me.

Thanks a lot for your quick answer !

1 Like

Works well in ios, both Safari mobile & webview !
Whan changing focus -> go to scene with a custom behavior that stop the ambient sound.

Not 100% working in Android, when changing focus, the sound stop, but when I return in the app, the app is relaunched from the begining…so it’s not the behaviour expected…

I post it also in the good topic.

(fyi - I removed from the other topic, we can just discuss here)

To clarify, you have an Android app and not using the chrome browser? Are you using your own code or a specific framework to build the app?

It is reloading the entire Hype document? Is the app itself reloading with it too? I’m not sure what control you have over Android lifecycle but you may want to use localStorage to save your state and restore if possible.

I Jonathan,

Yes, it’s an Android app with the chrome browser.
It’s a webview with a local storage in the app (in Android Assets).

No framework, just my own code.

The last scene name is saved with localStorage.
When changing focus :

		var handleVisibilityChange = (function () {
		if (document['hidden']) {

No pb to reload the good scene, the only pb is when I change focus, the app relaod the webview from the first scene and don’t go to the Mute scene.
It’s works fine in ios…

I’m going to re-check my @override onPause() & onBackPress()…

Thanks for your amazing app !!!

Ok, you’re right… to much focus for a focus problem blur my focus :sweat_smile:
It was a lifecycle pb.
I experiement a lot of possibilities to solve my pb in android studio, I leave bad code for onPause() & onBackPress()
Thanks for your fresh look ! :+1: