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?
Thanks in advance.
This answer https://stackoverflow.com/a/7620930/1459653 by @klaustopher (https://stackoverflow.com/users/767272/klaustopher) helped me. He wrote:
Here's how I implemented his advice so that clicking on the Font Awesome icon "fa-volume-up" (located on the Web page after "mule.") results in "donkey2.mp3" sound playing (note: mp3 doesn't play in all browsers).
If you only need to support recent browsers, then HTML 5 offers you the
Audio
objectto load/buffer your sound:
to play the sound:
to re-cue it to the beginning (so that you can play it again):
This code lets you put in a picture button; when click you get a sound. It works with Google Chrome and Microsoft Edge but I can't get it to work in Internet Explorer. I'm using html 5 codes; please copy and paste and add you own samples.
more on codes look at http://html5doctor.com/html5-audio-the-state-of-play/
You can use embed element for play sounds, but you've to check the formats supported by the different browsers.
Embed element on MDN
Example based on accepted answer (Tested in Chrome 70), but I didn't need to re-cue: