I have a problem more related to the browser than Babylon… I think. If I put a sound in Babylon to play this button appears:
Before, when the sound was made in HTML, there was no such problem. I just changed it for it to work directly through Babylon and I already have an audio on/off controller.
Google Chrome, Windows 10.
edit: If there is no way to fix this, can you tell me some condition with which I can control it? Well, it’s rendering two audios.
There can be multiple reasons for not playing your audio. Did you turn on your speakers? Ok, just joking!
So, did you try to debug the part of your code where you start the music? Is the condition met and does it run the getMusic.play() function? Is the getMusic variable correctly set? Is the audio ready to be played?
Handling the ‘ready to play’ callback function:
EDIT:
// this will not work
var music = new BABYLON.Sound("Violons", "sounds/violons11.wav", scene, null, { loop: true, autoplay: false });
music.play()
// this will
var music = new BABYLON.Sound("Violons", "sounds/violons11.wav", scene, () => {
music.play()
}, { loop: true, autoplay: false });
It starts normally, and I can start and stop the music from the controller. However, when I put it that piece of code doesn’t work anymore, nor does the autoplay. I don’t know what it could be.
Or you can use something like that - https://playground.babylonjs.com/#PCY1J#216
Here the music is playing after the any first pointer event since in order to play user has to interact with the page first.
Update: I managed, with a teammate, to get the above methods that @roland passed on to work. I had to use the “Engine.audioEngine.useCustomUnlockedButton = true” in the component where the 3D was running and the “unlock” method in the component where there was the start and stop button for the music. Now the only problem is that the music doesn’t start when you click on the scene. Thanks to everyone who has responded so far!
F.e., once you load that demo, click on the demo, then in MS Edge (based on Chrome) hit refresh. Then, without moving the mouse, click the demo. It will be muted, and the icon will appear.
@trusktr
If you refresh the webpage, it is a new “session”, and a user input is required again for sounds to play. Nobody wants to visit a website and be blasted with music and sounds without consent
On the contrary, all good experiences that I have ever tried in any browser always start with sound enabled as soon as possible. Never the opposite!
Babylon currently prevents this, because even after user interaction, sounds stay muted! That’s a bad experience considering that the user is already interacting with the experience.