views:

184

answers:

3

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....?

A: 

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/

resopollution
I'm afraid I tried this already, I've also tried keyup and all the other little bits n pieces, it just has me confused :(
Neurofluxation
I've tested it and updated my answer. Please let me know if the link I provided works for you.
resopollution
Hey, thanks for having a go at this, the code you provided works fine in IE, but with firefox 3.6.6 it makes the http connection to download the wav but no sound plays at all :( I'll have no hair by the end of this project!! lol
Neurofluxation
+2  A: 

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.

Samuel Meacham
Cheers, unfortunetely you are right :( - thanks.
Neurofluxation
A: 
// 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.

Brandon
(thinking along the lines of sound layering in flash)
Brandon
Thanks, this looks like the right way to do it (without being told to use flash by EVERYONE :). I now have the line: `$.sound.play("del.wav",{track: "track2", timeout:1000});` but it says that the syntax is slightly b0rked :(
Neurofluxation
I just tested this: $(function(){ $.sound.play("catpurr2.wav",{track: "track2", timeout:1000}); without error. Did you load the jQuery library before the plugin? And for the syntax problem, will be helpful if you know exactly where it is coming from. Using something like IE development toolbar debugger will be useful for script debugging - F12 on IE.
Brandon