Answer the question
In order to leave comments, you need to log in
Where is the error in my randomizer?
I want to randomly play the sound.
Some have already answered me, but unfortunately all their ways just crashed my client.
I decided to do it my way.
var arr = ["#bet1-sound","#bet2-sound","#bet3-sound"];
var rands = Math.floor(Math.random() * arr.length);
if (sound == 'on') {
$(arr[rands])[0].play();
}
<audio id="bet1-sound" src="/sounds/Stavka-1.mp3" preload="auto"></audio>
<audio id="bet2-sound" src="/sounds/Stavka-2.mp3" preload="auto"></audio>
<audio id="bet3-sound" src="/sounds/Stavka-3.mp3" preload="auto"></audio>
Answer the question
In order to leave comments, you need to log in
I would do with the Ion.Sound plugin . Like this:
var names = ["Stavka-1", "Stavka-2", "Stavka-3"];
ion.sound({
sounds: [
{name: names[0]},
{name: names[1]},
{name: names[2]}
],
volume: 1,
path: "/sounds/",
preload: true
});
var rand = Math.round(Math.random() * (names.length - 1));
ion.sound.play(names[rand]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question