S
S
Sergeevich862014-08-05 11:52:01
HTML
Sergeevich86, 2014-08-05 11:52:01

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

3 answer(s)
A
Alexander Taratin, 2014-08-05
@Taraflex

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");
})

A
Anna Bakurova, 2014-08-05
@Libris

and the standard html5 menu for audio does not work?

D
Denis Ineshin, 2014-08-05
@IonDen

Use the javascript plugin

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question