Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 16th, 2012  |  syntax: None  |  size: 0.85 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Preload MP3 File before using the Play button
  2. function preloadSound(src) {
  3.     var sound = document.createElement("audio");
  4.     if ("src" in sound) {
  5.         sound.autoPlay = false;
  6.     }
  7.     else {
  8.         sound = document.createElement("bgsound");
  9.         sound.volume = -10000;
  10.     }
  11.     sound.src = src;
  12.     document.body.appendChild(sound);
  13.     return sound;
  14. }
  15.        
  16. function loadSound (src) {
  17.     var sound = document.createElement("audio");
  18.     if ("src" in sound) {
  19.         sound.autoPlay = false;
  20.     }
  21.     else {
  22.         sound = document.createElement("bgsound");
  23.         sound.volume = -10000;
  24.         sound.play = function () {
  25.             this.src = src;
  26.             this.volume = 0;
  27.         }
  28.     }
  29.     sound.src = src;
  30.     document.body.appendChild(sound);
  31.     return sound;
  32.  }
  33.        
  34. var sound = loadSound("/mySound.ogg");  //  preload
  35. sound.play();