HTML5 Not playing sounds when scene is loaded.

ConquistadorBob

  • Posts: 21
In the title screen for my game, I have background music. This event is how I start playing that music.
But it only plays once you click anywhere on the screen. For example, you start the game and the title screen loads, but unless you interact with the screen, clicking a button or something, it won't play the song. It plays the song from the beginning when you do this. Meaning it does not play the song, and only let you hear it once you click on the screen, It only starts the song once you click on the screen. I tried putting this code in when updating event and every n seconds, but it still does nothing. This is only a problem when I have my game in HTML5, in Flash the music always plays when you start the game.
https://conquistadorbob.github.io/TigerLilly/
 I have put the game in its work in progress state here so you can see for yourself what happens. I spent a long time looking here and seeing other people have similar problems to mine, but no one gave solutions that worked to those problems. The files are OGG files btw. Does anyone have any idea why this is happening>

rob1221

  • *
  • Posts: 9472
Browsers have made changes to restrict autoplaying audio/video so it's probably that.  If I open the link in a new tab I don't hear audio until I switch to that tab.

ConquistadorBob

  • Posts: 21
Browsers have made changes to restrict autoplaying audio/video so it's probably that.  If I open the link in a new tab I don't hear audio until I switch to that tab.
I think you're right. When I asked some of my friends to test this out they had inconstant experiences.  Some of them never heard any sound unless the sound button was turned off and on again. Some heard the sound after the game started, just not on the title screen. Is there anyway around this? Or at least some way to make it consistent?

rob1221

  • *
  • Posts: 9472
You could try the focus event (Input > Universal > Focus) and then play the music there if not already playing.