Answer the question
In order to leave comments, you need to log in
How to make audio play on pressing a certain key?
In general, the essence is this.
There is a stream in *.mp3 format. How can I make this stream play by pressing the key?
It is desirable that the code is not very large, and by adding the function of adding sound, you do not have to insert the same amount of code.
I've been googling for an hour and can't find anything.
Answer the question
In order to leave comments, you need to log in
function playSound(url){
var s = new Audio();
s.src = url;
s.play();
}
$(document).keypress(function (e) {
if (e.which == 55 || e.which == 191)
playSound("someSoundUrl.mp3");
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question