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
orfalse
: whether the audio clip should start playing at the beginning whencurrentTime
reaches theduration
.autoplay
true
orfalse
: whether the audio should start playing automatically when it has loaded.muted
true
orfalse
: Setting this totrue
silences theaudio
object regardless ofvolume
settings.controls
true
orfalse
: Displays controls for anaudio
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 between0
and1
.paused
true
orfalse
: whether theaudio
object is paused. Set with a call to thepause()
function.ended
true
orfalse
. Set when anaudio
object has played through its entireduration
.currentSrc
URL to the source file for the
audio
object.preload
Specifies whether the media file should be loaded before the page is displayed. At the time of this writing, this property has not been implemented across all browsers.
Note
To see which properties and events of the HTMLMediaObject
are supported in which
browsers, visit this
site.
Get HTML5 Canvas, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.