HTML and CSS Reference
In-Depth Information
Audio Functions
load()
Starts loading the sound file specified by the
src
property of the
<audio>
tag.
play()
Starts playing the sound file specified by the
src
property of the
<audio>
tag. If the
file is not ready, it will be loaded.
pause()
Pauses the playing audio file.
canPlayType()
Accepts a MIME type as a parameter, and returns the value
maybe
or
probably
if
the browser can play that type of audio file. It returns
“”
(an empty string) if it
cannot.
Important Audio Properties
There are many properties defined for the
audio
element in HTML5. We are going to
focus on the following because they are the most useful for the applications we will
build:
duration
The total length, in seconds, of the sound represented by the
audio
object.
currentTime
The current playing position, in seconds, of the playing audio file.
loop
true
or
false
: whether the audio clip should start playing at the beginning when
currentTime
reaches the
duration
.
autoplay
true
or
false
: whether the audio should start playing automatically when it has
loaded.
muted
true
or
false
. Setting this to
true
silences the
audio
object regardless of
volume
settings
controls
true
or
false
. Displays controls for an
audio
object in an HTML page. Controls
will not display on the canvas unless they are created in HTML (for example, with
a
<div>
overlay).
volume
The volume level of the
audio
object; the value must be between
0
and
1
.
paused
true
or
false
: whether the
audio
object is paused. Set with a call to the
pause()
function.