Hi everyone,
I gave a go to create a piano with HTML,CSS and js and I’ve wasted hours trying to figure out why my code (in /localhost:8000/) wasn’t working and finally using a different browser than chrome…all sorted, piano is playing using the keyboard as I want!
following my code:
function playSound(e) {
const audio = document.querySelector(`audio[data-key="${e.keyCode}"]`);
if (!audio) return;
audio.pause();
audio.currentTime = 0.5;
audio.play();
}
document.addEventListener("keydown", playSound);
on Chrome the error displayed in the console is : “Uncaught (in promise) DOMException: The play() request was interrupted by a call to pause().” After reading here and there I still struggling to understand how to sort it in chrome. Anyone willing to help me out?
thanks!!