html5 - want to play audio and it should be stop after 10 seconds inHtml and javascript? -


i new in html5 , javascript want play audio clip when open html page , should stop after 10 seconds , display message audio play successfully.

for simple audio play in html5 below

<!doctype html> <html> <body>   <audio controls>   <source src="kill_bill.mp3" type="audio/mpeg"> browser not support audio element. </audio> <script> setinterval(function(), 10000);  $.each($('audio'), function () { this.stop(); alert('audio stop successfully'); });    </script>  </body> </html> 

a settimeout seems more appropriate :

var audio = document.createelement("audio"); audio.src = "sound.mp3";  audio.addeventlistener("canplaythrough", function () {         settimeout(function(){             audio.pause();             alert("audio stop successfully");         },         10000); }, false);  

example


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -