HTML5 audio overview
Before we start writing our piano application, we need to learn the basics of how to use HTML5 audio. So let's start with an overview of the <audio>
element and its API.
The HTML5 <audio> element
The HTML5 <audio>
element is used to define an audio file to play in your web page or application. The audio
element can have visible controls on the page or it can remain hidden and be controlled from JavaScript. Here are a few of the most useful attributes it supports:
src
: URL of the audio file to load.autoplay
: Used to specify that the file should start playing as soon as it's loaded.controls
: Tells the browser to display audio controls on the page. Otherwise, nothing is displayed for the element.loop
: Specifies that the audio will play in a loop.muted
: Specifies that the audio will be muted.preload
: Defines how the audio file is loaded.auto
: Loads the audio file when the page loads. This is the default.none
: Does not preload the file, waits until...