audio - Output sound using JavaScript -


this question has answer here:

i want make online metronome using javascript. people around me started needing them there isn't decent 1 doesn't use flash. thought why not.

before starting want make sure it's possible javascript. need know if it's possible output sound, if rest should simple enough.

so possible? if yes, how?

p.s.: checked html5 audio tag , don't think it's gonna work. it's not 1 long file metronome sounds. it's loop runs sound every time should.

the audio tag right tool this:

https://developer.mozilla.org/en-us/docs/web/html/element/audio

create audio tag - like:

<audio id="m" loop>     <source src="metronome.mp3"> </audio> 

and either make loop using appropriate options on tag (loop), or can script in js:

<script> // goes inside whatever event handler - when user clicks button, timer, etc. document.getelementbyid('m').play(); // play sound </script> 

this article provides introduction:

http://html5doctor.com/native-audio-in-the-browser/

if need work in older browsers, can resort using flash (which "traditionally" how sort of thing has been done). mention - it's idea avoid new development. audio tag supported in ie9+ , chrome, ff, safari, opera.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -