The sound example is somewhat problematic

The following sound example doesn’t work in the first time/run. It only works in the second time/run. Why?

var createScene = function () {

var scene = new BABYLON.Scene(engine);

var camera = new BABYLON.FreeCamera(“FreeCamera”, new BABYLON.Vector3(0, 0, 0), scene);

var music = new BABYLON.Sound(“Violons”, “sounds/violons11.wav”, scene,

function() {

// Sound has been downloaded & decoded

            music.play();

        }

);

return scene;

};

The sound example on the playground, from which the code was taken (I assume), is working on first try in most environments. On mobile there is sometimes a punishing that need to be granted before it works.

What browser are you using? Any console errors? Anything else to report?

Here is what I did.

  1. Copy the code
  2. Paste at the JS Babylon Playground console
  3. Clicked the arrow button that runs the code
  4. Clicked unmute the sound --> NO SOUND
  5. Clicked the arrow button that runs the code
  6. Sound comes out.

It’s very consistent that on any desktop browser, the sound only loads the second time through.

IN ADDITION, I tried to use the same logic for my game. In all instances, JSFiddle and the live sites on desktop, the sound doesn’t play the first time…until I reach another instance to play sound, then it plays. In other words, it doesn’t play automatically (even when it’s ready).

This is expected. The first time you play the sound the browser will not let you do it. We detect it and we propose the user to click. If you want to be sure the sound is played the first time it HAS to be from a user initiated event (like a click)