scratchy play/pause using <audio>

I'm making a game where one of the challenges is to play a short song using the computer keyboard. So far I'm using royalty-free piano key recordings from archive.org. The sound quality is acceptable in Windows media player. But when I use JavaScript in Squiffy, I get a lot of side-effects, like delayed play, static, and scratchy pauses. Is there anything I can do about this other than buy a faster computer? My unimpressive code looks like this.

    document.addEventListener('keydown', function(zero) {
        if (zero.code === 'Digit0') {
        document.getElementById('E2').play();  //E2 is the id of the .ogg of piano key E2.
    }
    });
    document.addEventListener('keyup', function(zero) {
        if (zero.code === 'Digit0') {
        document.getElementById('E2').pause();
        document.getElementById('E2').currentTime = 0;
    }
    });

Thanks, wonderful people.


Looks nice. *Tries not to look totally clueless *

:)


Come now, Bluevoss. I've learned tons of tricks in Squiffy, HTML, and Javascript from you over the years. And your games give me genuine pause.


Too kind, sir!


By the way, did you try private messaging The Pixie about your upload problem?


Yes, I dug around and found his message link and posted him. Nothing back yet.


Log in to post a reply.

Support

Forums