scratchy play/pause using <audio>

IFforClassroom
16 May 2022, 06:17

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.


Bluevoss
16 May 2022, 16:59

Looks nice. *Tries not to look totally clueless *

:)


IFforClassroom
17 May 2022, 04:38

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.


Bluevoss
18 May 2022, 13:59

Too kind, sir!


IFforClassroom
18 May 2022, 14:38

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


Bluevoss
19 May 2022, 02:33

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