scratchy play/pause using <audio>
IFforClassroom
16 May 2022, 06:17I'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.
![](https://i.imgur.com/6mfIIbhb.gif)
Bluevoss
16 May 2022, 16:59Looks nice. *Tries not to look totally clueless *
:)
IFforClassroom
17 May 2022, 04:38Come 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.
![](https://i.imgur.com/6mfIIbhb.gif)
Bluevoss
18 May 2022, 13:59Too kind, sir!
IFforClassroom
18 May 2022, 14:38By the way, did you try private messaging The Pixie about your upload problem?
![](https://i.imgur.com/6mfIIbhb.gif)
Bluevoss
19 May 2022, 02:33Yes, I dug around and found his message link and posted him. Nothing back yet.