Sound issue on iOS

Hello all,

I am trying to play a sound after a prompt which asks the user a question. It should either play a correct sound or a buzzer sound.

It all works perfectly on android and PC but on iOS/Mac all sound disappears after the prompt appears.

Here is the simplified code that is causing the issue

var soundEntity ='soundEntity');
let answer = prompt('How much is 1 + 1?');
if (answer == 2) {'correct');
 } else {'wrong');

Does anyone know why this could be and how to solve it?

Without the prompt pop-up it works fine.

I tried the following:

  • Already playing the sound before the prompt on volume 0 so that it is already loaded
  • Using setTimeout to play the sound later

Audio won’t play without a user interaction on the browser. Maybe that’s the issue here?

Yeah indeed I probably have to look in that direction. It only works with user interaction AND it has to be synchronous. So the solution will probably be some kind of workaround.

I’ve not seen the application but if you have a title screen where the user presses a button to start the game, that would be enough to allow sound to be played through the whole session

Also, I would double check that the mute switch on the phone is not toggled. That has caught a number of devs out including me!

Thank you Yaustar, I appreciate. I don’t have a start button I will try some things and post the solution here if I find one.

@yaustar is there any way to check if the user’s device is switched to mute? I have checked with a website made with HTML and .js, its audio is playing fine on switching on mute, but cannot hear audio played from app made using sound component of PlayCanvas.

As far as i know, there is not a way to know if the device is muted on iOS but there is a way to play PlayCanvas audio whike it is muted. See IOS force play audio even with mute switch toggled · Issue #4678 · playcanvas/engine · GitHub

Thank you for the solution