Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Immediate play sound on button click in HTML page

In my HTML page I have 9 images for dialing numbers and one text box that shows the pressed numbers. I want each of those images to immediately play beep sound when users click on them. I tried to use embed with hidden property and navigate it's source to .wav sound.

It is working OK, but when I press the images one after another immediately, it cannot play sound and just bees once at the end.

Is there any faster way of playing a .wav sound on 'onclick' method?

like image 816
firefalcon Avatar asked Oct 18 '12 11:10

firefalcon


People also ask

How can I play sound when my button is clicked?

You can use any audio. Then a global constant of buttons is set. Then the sound in the 'audio' is linked to the button by the onclick event. Then I have used the play () method here to play the audio.

How do I add a click sound to my website?

An easy way to embed audio on a website is by using a sound hosting site, such as SoundCloud or Mixcloud. All you need to do is upload the file and receive an HTML embed code. Then copy and paste the embed code into the web page's code or WYSIWYG site editor.

How you can use JavaScript to play the sound for the button selected?

Hello everyone, In this post, we will examine how to solve the How You Can Use Javascript To Play The Sound For The Button Color Selected problem using the computer language. var audio = new Audio("play. mp3"); audio. play();


1 Answers

If you only need to support recent browsers, then HTML 5 offers you the Audio object

to load/buffer your sound:

var snd = new Audio("file.wav");

to play the sound:

snd.play();

to re-cue it to the beginning (so that you can play it again):

snd.currentTime=0;
like image 92
paul Avatar answered Oct 12 '22 01:10

paul