title: Playing a simple sound with web audio api
body: <p>I've been trying to follow the steps in some tutorials for playback of a simple, encoded local wav or mp3 file with the web Audio API using a button. My code is the following (testAudioAPI.js):</p>
  
  <pre><code>window.AudioContext = window.AudioContext || window.webkitAudioContext;
  var context = new AudioContext();
  var myBuffer;
  
  clickme = document.getElementById('clickme');
  clickme.addEventListener('click',clickHandler);
  
  var request = new XMLHttpRequest();
  
  request.open('GET', 'WoodeBlock_SMan_B.wav', true);
  
  request.responseType = 'arraybuffer';
  
  // Decode asynchronously
  request.onload = function() {
    context.decodeAudioData(request.response, function(theBuffer) {
      myBuffer = theBuffer;
    }, onError);
  }
  request.send();
  
  function playSound(buffer) {
    var source = context.createBufferSource(), g = context.createGain();
    source.buffer = buffer;
    source.start(0);
    g.gain.value = 0.5;
    source.connect(g);
    g.connect(context.destination);
  }
  
  function clickHandler(e) {
      playSound(myBuffer);
  }
  </code></pre>
  
  <p>And the HTML file would look like this: </p>
  
  <pre><code>    &lt;!doctype html&gt;
  &lt;html&gt;
      &lt;body&gt;
          &lt;button id="clickme"&gt;Play&lt;/button&gt;
          &lt;script src='testAudioAPI.js'&gt;&lt;/script&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>However, no sound is achieved whatsoever. I've tried several snippets but I still can't figure it out. When I try to generate a sound by synthesizing it by creating an oscillator node, I do get sound, but not with buffers from local files. What would be the problem here? Thank you all. </p>