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 });
Here my code to make sound works:
This is called inside Babylon 3D ambient.
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!