I'm using
document.addEventListener('keydown', function(e) {
if (e.keyCode == 65) {
notedo.play()
}
});
which essentially just plays a sound on keypress, however I'm trying to create sampler and there's a delay pressing a key. Anyway I can get around this? as well as being able to play multiple keys at once?
I am also using this in my HTML side:
<div class="black key" data-note="G#3" onclick="notedo.play()"></div>
So when clicking on my div element above it plays the notedo variable in javascript. I'm trying to find a way to implement key pressing to play the sound as well.
Found my issue which I think was getting confused with delay.
I was actually trying to play the same audio immediately after I press the same button.
I ended up using this!
document.addEventListener('keydown', function(e) {
if (e.keyCode == 65) {
notedo.play()
}
if (e.keyCode == 65) {
notedo.play();
notedo.currentTime = 0
}
});