Im trying to make this audio play when a specific key is pressed and will continue to loop. Any ideas on how to make this work?
document.addEventListener("keypress", function(event) {
if (event.keyCode == 13) {
<audio controls loop>
<source src="Chiptronical.ogg" type="audio/ogg">
</audio>
}
});
i wanted it to play the audio when the key is pressed but it just doesnt work
2
Answers
try this and run on browser. and press enter.
make sure directory is same with audio file
You can achieve the desired results like this:-
Here is the html:-
Here is the JavaScript:-