Play audio and restart it onclick - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Audio

Description

Play audio and restart it onclick

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body> 
      <audio id="audio1" src="http://your test.mp3"></audio> 
      <button onclick="play()">play</button> 
      <script type="text/javascript">
function play() {//  ww w . jav a 2  s . c  o  m
    var audio = document.getElementById('audio1');
    if (audio.paused) {
        audio.play();
    }else{
        audio.pause();
        audio.currentTime = 0
    }
}

      </script>  
   </body>
</html>

Related Tutorials