Reputation: 10713
I have this code:
$('#typer').keypress(function(e){
var code = (e.keyCode ? e.keyCode : e.which);
if (code == '13') {
$.sound.play("cr.wav",{timeout:1000});
} else if (code == '8') {
$.sound.play("del.wav",{timeout:1000});
} else if (code == '27') {
$.sound.play("asswipe.wav",{timeout:1000});
} else {
$.sound.play("key.wav",{timeout:1000});
}
});
Now, for some reason - I can only type one character in this box. The sound plays once and then nothing more.
This works fine in IE... Just FireFox...
Plugin link: http://code.google.com/p/jqueryjs/source/browse/trunk/plugins/sound/jquery.sound.js?r=5750
Has ANYONE ever used this plugin....?
Upvotes: 2
Views: 1110
Reputation: 5500
// play a sound from the url, on a track, stopping any sound already running on that track
$.sound.play(url, {
track: "track1"
});
Above is the documentation from the plugin you're using.
Did you try playing each sound on a new track?
I'd create a new name for each track on every keypress function and assign the sound src to that new track.
Upvotes: 0
Reputation: 10415
First, e.which is a number, not a string, so you should lose the single quotes: use code == 13
, not code == '13'
. You might be better served by a switch statement (though that's just a matter of preference).
Second, I don't think the problem is with the plugin. Without using the plugin, this has the same problem:
$('#typer').keypress(function(e) {
var snd = $('<embed hidden="true" loop="false" src="key.wav" autostart="true" height="0" />');
snd.appendTo("body");
setTimeout(function() { snd.remove(); }, 1000);
});
It seems that FF and Chrome do not deal well with having <embed>
tags added to them dynamically. You may want to look for a different plugin, one that doesn't use the tag. I'm not a fan of flash, but there are probably some plugins out there that use it, and that work well.
Upvotes: 2
Reputation: 20350
Perhaps try keydown instead of keypress? I've had lots of problems using keypress working on a RPG sprite character movement project with numbers not matching to the expected key and just abandoned it altogether in favor of keydown.
If that doesn't work I can look into replicating your environment.
Edit: This seems to work for me (Chrome & Firefox 3.6): http://resopollution.com/experiments/sound/sound.html
I did notice ONCE that the page simply opened up the audio file (seems buggy), but can't replicate it. Perhaps that is what you are experiencing... It works fine now for me.
If you still experience problems...
Alternative 1 You may be able to change the invisible tag (in the plugin) to an invisible that links to a page which has your wav file with autoplay on and no loop.
Alternative 2 Use an html5/flash option. http://www.schillmania.com/projects/soundmanager2/
Upvotes: 0