Playing Audio from a URL source using the Web Audio API - A Minimal Example

January 2014: This tutorial has been expanded - take a look at Play an Audio file using JavaScript on my tutorial site Web Apprentice

The HTML5 <audio> tag is the easiest way to play audio from a URL source but it is quite limited in scope.

If you want to manipulate and, in particular, generate audio then you want to use the Web Audio API.

This can quickly get very complicated, so here is a minimal example that uses the API to pull an audio file from a remote URL, store the audio data into memory and then play the audio when a button is clicked.

Look at the Source for this page for more detail.

Here are some online resources with which to learn more:
Apple - Using_HTML5_Audio_Video.pdf
W3C Web Audio API specification