Search code examples
javascriptmp3touch-event

Play MP3 on touch event with HTML-CSS-JS


could someone help me in finding a way to play an mp3 audio file by touching an image on a touch screen with HTML-CSS-JavaScript?

Thank you!


Solution

  • <!DOCTYPE HTML>
      <html>
      <head>
      <title>audio with image</title>
      </head>
      <body>
    
        <script>
      function play(){
           var audio = document.getElementById("audio");
           audio.play();
                     }
       </script>
    
    <img src="http://www.partyplan123.com/wp-content/uploads/2015/02/click-here.jpg" onclick="play()">
    <audio id="audio" src="http://kolber.github.io/audiojs/demos/mp3/juicy.mp3" ></audio>
     </body>
     </html>