Phaser 3 - How am I doing AudioContext stuff wrong?

Hi! I have this project I’ve been working on and I’m having a hard time getting it to work well with I’m pretty sure the Webkit autoplay policy stuff. It actually works for me fine in Chrome, but not Safari or iOS. Safari won’t even show some stuff in the console that Chrome will regarding the AudioContext. Can someone point me in the right direction? Thanks :slight_smile:

http://files.masonsklar.com/local/

1 Like

Yeah I am having the same problem: the app I’m working on doesn’t want to play sound on iOS (I posted about this separately). Desktop Chrome will complain in the console, but eventually plays sound. The examples on the labs work fine, but copy-pasting that code directly doesn’t work - so it must be something else (in the HTML, presumably).

Possible answer (worked for me, can’t say whether it will for you):

			this.input.addDownCallback(function() {
				
				if (game.sound.context.state === 'suspended') {
					game.sound.context.resume();
				}
				
			});

Before y’all think I didn’t bother to read the documentation or even the warning given, I had that exact code bound to “pointerdown” and/or “pointerup” - but apparently that doesn’t cut it.

Thanks! I figured it out! I was having a hard time getting Safari to accept that a click in Phaser was a gesture worthy of resuming the AudioContext. I made sure that the AudioContext was created before my game and made it so that clicking on a div starts the game and resumes the AudioContext.