Hello all,
In my script I’ve created a variable of sound array: private _soundArray : Sound [];
Then from the constructor, I call the method which loads the audio files into the array.
Once player clicked a button, the first element of the sound array needs to play.
I’ve testes playing the audio with autoplay and the audio path is correct.
I’ve first populated the array:
this._soundArray = [
new Sound("name1", "./sounds/Teleport1.mp3", scene),
new Sound("name2", "./sounds/Teleport1.mp3", scene),
new Sound("name2", "./sounds/Teleport1.mp3", scene)
];
Logger.Warn("sound count is" + this._soundArray.length);
Once player click the button, this method is called:
public playSoundOnPlayerInput(): void {
Logger.Warn("first audio is played" + this._soundArray[this._audioIndex].name);
this._soundArray[this._audioIndex].play();
this._audioIndex++;
}
The log for the sound count is correct and shows there’s 3 sounds in the array.
In the playSoundOnPlayerInput(), the log for finding the name of the first sound is correct, but the sound would not play and will not give any error in the console.
Going back to the playground prototype, I see that when I create the sound and use the function to play - it works:
var voice1 = new BABYLON.Sound "TeleportSound",
"https://raw.githubusercontent.com....mp3",
scene, function ()
{voice1.play();
});
the sound starts playing, but if I don’t use function, and start a new line and simply write voice1.play();
it will not play.
Thanks you