Advertisement
lalatino

example for using html5 audio tag

Jul 14th, 2013
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.03 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.   <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  5.   <title> http://jsfiddle.net/F35Fw/1/ - jsFiddle demo</title>
  6. <script type='text/javascript'>//<![CDATA[
  7. function test(e) {
  8.     var c = (typeof e.which == "number") ? e.which : e.keyCode;
  9.     if (c!=13) {
  10.         return;
  11.     }
  12.     var soundList = [
  13.         'correct_password.mp3',
  14.         'wrong_password.mp3' ];
  15.     var ae = document.getElementById('audioplayer');
  16.     if (document.getElementById('password').value == 'pass') {
  17.         ae.setAttribute("src", soundList[0]);
  18.     } else {
  19.         ae.setAttribute("src", soundList[1]);
  20.     }
  21.     ae.play()
  22. }
  23. //]]>  
  24. </script>
  25. </head>
  26. <body>
  27.     <input type="text" id="password" placeholder="Enter Password (pass)" onkeyup="test(event)" />
  28.     <div id="audiocontainer">
  29.     <audio id="audioplayer"></audio>
  30.     </div>
  31.  
  32.     <!-- for flash fallback for compatibility with older browser with audio tag support look also here:
  33.     http://stackoverflow.com/questions/17387702/html5-audio-song-only-playing-first-2-in-array
  34.         -->
  35.  
  36. </body>
  37. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement