Web Audio API how-to: Playing audio based on user interaction

1 · Eric Bidelman · Nov. 28, 2011, midnight
One thing the Web Audio API does particularly well is play sound. Of course, this is something you’d expect from an audio API :). That said, the API is complex and it’s not immediately obvious on the best way to do something simple like load a sound file and play it based on a button click. That task alone can involve a number of new platform features likes XHR2, FileReader API, and ArrayBuffers. So…I threw together a quick example on how to load a audio file and play/stop it based on the user c...