title: Reusing HTML5 Audio Object in Mobile Safari
body: <p>I want to play a short (less than 1s) audio file in response to user input on my web app running in Mobile Safari on the iPad with minimum latency between event and audio playback. The playback can be triggered multiple times between page reloads, therefore I want to cache the audio file.</p>
  
  <p>The following plays the file on the first click but after than nothing happens:</p>
  
  <pre><code>var audio = new Audio("ack.mp3");
  $("#button").click(function(e) {
    e.preventDefault();
    audio.play();
  }
  </code></pre>
  
  <p>If I add an event listener to the "ended" event which reloads the file I can get two playbacks from the same object and then silence:</p>
  
  <pre><code>var audio = new Audio("ack.mp3");
  audio.addEventListener('ended', function() {
    audio.load();
  }, false);
  $("#button").click(function(e) {
    e.preventDefault();
    audio.play();
  }
  </code></pre>
  
  <p>If I manually set the currentTime attribute to 0 like this:</p>
  
  <pre><code>var audio = new Audio("ack.mp3");
  audio.addEventListener('ended', function() {
    audio.currentTime=0;
  }, false);
  $("#button").click(function(e) {
    e.preventDefault();
    audio.play();
  }
  </code></pre>
  
  <p>I get the following error in the error console:</p>
  
  <pre><code>INDEX_SIZE_ERR: DOM Exception 1: Index or size was negative, or greater than the allowed value.
  </code></pre>
  
  <p>Any ideas on how to make this work? Thanks in advance</p>