Reputation: 1484
I am playing a sound through javascript with this code
var snd = new Audio("flip.mp3"); // buffers automatically when created
snd.play();
All is well, but I want to play the sound lots of times, so each time a user clicks on an object, the sound is played. This works for about 20 times, but then the sound doesn't play at all. Does anyone have any idea as to what the problem could be?
Upvotes: 1
Views: 571
Reputation: 3949
You should globally declare :
var snd = new Audio("flip.mp3");
Then call play in a function on click:
function playSound() {
snd.play();
}
Upvotes: 2