Reputation: 31
I have a menu with a mouseouver event that triggers a sound file to start playing. Trouble is if the user mouseover another one of the links in the menu, the sound plays again.
What I am trying to figure out is how to only play one sound at a time? ie. wait until current sound has finished playing before starting it again?
Any ideas?
Here the code that I have in place at the moment. It uses the jQuery.sound.js plugin.
.mouseover(function(){
$.fn.soundPlay({url: 'images/casino.wav'});
})
cheers! Dec
Upvotes: 3
Views: 1148
Reputation: 22016
Not sure if you can wait for the soundPlay function to end like normal jquery functions.
If you know how long the sound lasts I would look to have a variable which is turned on and off using the known duration:
var soundPlaying = false;
.mouseover(function(){
if (!soundPlaying) {
$.fn.soundPlay({url: 'images/casino.wav'});
soundPlaying = true;
setTimeout('soundPlaying = false;',1000);
}
});
I have assumed 1000 ms as the duration of the sound being played.
Upvotes: 0
Reputation: 104178
The only way to do this is to have a callback that will fire when the sound has stopped playing. However, I don't think that there is a plugin that supports something like this:
$.fn.soundPlay({url: 'images/casino.wav',
finishedPlaying: function() {}});
If you had this, you could disable mouseover when a sound starts playing and enable it again when it finishes.
Upvotes: 1