Discord
Login
Community
DARK THEME

Mobile sound issues

I'm having some sound issues, especially on apple devices. I'm aware that many browsers prevent audio from playing automatically without the user first providing some input. However, I've noticed some major differences between the mobile devices I've tried my games on:

  • When my games are installed as a pwa on my android phone, I have no problems at all. If the game is not installed and is simply accessed via a browser link, sound won't play until the game goes into fullscreen mode. This is fine, for me at least.

  • On iphone (even when installed as a pwa), sounds only play after tapping the screen; the audio context is not activated when the first gesture is a drag rather than a tap. Once a tap is registered, the audio context is activated and the game will start playing sounds.

  • On ipad (even when installed as a pwa), only the first interaction counts. If it was a tap, then sound will play. If it was a drag, then sound will NEVER play, even with subsequent taps.

A game with only tap based input (https://microstudio.dev/i/arhodes/concentration/) will play sound just fine on all devices (with ipad occasionally messing up).

A game with only drag based input (https://microstudio.dev/i/arhodes/puppuzzles/) will NEVER play sound on iphone/ipad unless the user knew all of these caveats beforehand. This is a bit of a problem for me.

I know safari/webkit is notorious for poor handling of games, audio, background processes, and pwa's. Still, is there any way around this besides encouraging the first interaction to be a tap? It seems silly to add a "click to play" title screen just to get sound to work, especially when it won't always achieve that (if the user slips and drags their finger across the play button, for example).

I noticed that in the exported html5 zip, AudioCore.prototype.getContext (lines 5609-5639 in microengine.js) adds event listeners to "touchend" and "mouseup". Is there a reason that it only listens for those and not, for example, touchstart? Could it be that ios/ipados is not handling touchend events as expected? Sorry, I know this is technical, but my time is limited and I wanted to see if anyone else had a solution before I started digging deeper into the engine.

I just tried it, and changing the event listener on lines 5633 and 5637 of microengine.js to "touchstart" does fix the issue on ipad. I'll probably make a pull request for this, but I'll have to study the codebase a bit first because I don't fully understand the build process yet.

(Should have put the "bug" tag on this, sorry)

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community