Tag: Audio

HTML5 Series - Audio

Traditionally if you wanted Audio on your page you would embed it in a Flash object. But when Steve Jobs declared that the iPhone would never support Flash or any other plug in's, there was suddenly a demand that browsers would need to support this natively and in a consistent way between browsers.

In HTML5 we can do this using the Audio tag. e.g.

1<audio controls>
2 <source src="url of the file" type="audio/mp3">
3 Your browser doesn't support audio.
4</audio>

The above example demonstrates setting the file source for the audio with the source tag, the controls tag tells the browser to show audio controls and there is also some text that will be displayed if the browser doesn't support audio.

It is also possible to set multiple source tags to reference different file formats as not all browsers support the same ones. Alternatively when setting just one source, a src tag can be placed on the actual audio node rather than as a child element.

Other settings which could be set include:

autoplay - determines if the file should start playing on the page load
loop - specifies that the file should repeat when it's finished
preload - instructs the browser to start downloading the audio file when the page has loaded