joshwcomeau / use-sound

A React Hook for playing sound effects
MIT License
2.6k stars 97 forks source link

On IOS, after switching activities, sounds are not played anymore #15

Closed myagoo closed 4 years ago

myagoo commented 4 years ago

I did not encountered the issue myself and I tried to gather as much informations as possible.

When switching activities on IOS (tested on 13.4.1), sounds does not play anymore. The only found workeround so far is to refresh the page.

So far it seems to affect all IOS users, the issue was encountered on my app but also on https://joshwcomeau.com/

Everything works fine on android.

joshwcomeau commented 4 years ago

Interesting!

What do you mean by switching activities? Do you mean switching to a different application (not Safari) on iOS, and then switching back to the browser?

My guess is that this is either a Safari restriction (not able to resume sounds after the window is unfocused) or maybe a bug in Howler. I don't think this code would be responsible for that...

Will leave this issue open in case anybody else discovers a workaround, but I won't be actively investigating. Thanks for the heads-up!

myagoo commented 4 years ago

I meant switching to a different application or going back to homescreen, yes.

After further investigation, the issue is also present on https://howlerjs.com/#sprite but not on any demo of http://www.schillmania.com/projects/soundmanager2/

myagoo commented 4 years ago

Also, I've found similar issues https://github.com/goldfire/howler.js/issues?q=is%3Aissue+is%3Aopen+ios

https://github.com/goldfire/howler.js/issues/1234 https://github.com/goldfire/howler.js/issues/1171

joshwcomeau commented 4 years ago

Appreciate the digging-around—yeah, I'm going to close this, since it seems like something best addressed at the Howler level.

In the meantime, maybe a workaround could be to pause sounds when the browser window loses focus? Not sure how this would work, but if anyone wants to explore, please share findings here!