HTML DOM Audio Object

Audio object

The Audio object is a new object in HTML5.

The Audio object represents the HTML <audio> element.

Access Audio object

You can access the <audio> element by using getElementById():

var x = document.getElementById("myAudio");

Try it yourself

Create Audio object

You can create an <audio> element by using the document.createElement() method:

var x = document.createElement("AUDIO");

Try it yourself

Audio object properties

Attributes Description
audioTracks Return the AudioTrackList object representing the available audio tracks.
autoplay Set or return whether the audio should be played immediately after loading.
buffered Return the TimeRanges object representing the buffered parts of the audio.
controller Return the MediaController object representing the current media controller of the audio.
controls Set or return whether controls (such as play/pause) should be displayed.
crossOrigin Set or return the CORS settings of the audio.
currentSrc Return the URL of the current audio.
currentTime Set or return the current playback position of the audio (in seconds).
defaultMuted Set or return whether the audio is muted by default.
defaultPlaybackRate Set or return the default playback speed of the audio.
duration Return the length of the audio (in seconds).
ended Return whether the playback of the audio has ended.
error Return the MediaError object representing the audio error state.
loop Set or return whether the audio should play again at the end.
mediaGroup Set or return the name of the media group to which the audio belongs.
muted Set or return whether the sound is muted.
networkState Return the current network state of the audio.
paused Set or return whether the audio is paused.
playbackRate Set or return the playback speed of the audio.
played Return the TimeRanges object representing the played part of the audio.
preload Set or return the value of the audio's preload attribute.
readyState Return the current ready state of the audio.
seekable Return the TimeRanges object representing the seekable part of the audio.
seeking Return whether the user is currently seeking in the audio.
src Set or return the value of the audio's src attribute.
textTracks Return the TextTrackList object representing the available text tracks.
volume Set or return the volume of the audio.

Audio object methods

Method Description
addTextTrack() Add a new text track to the audio.
canPlayType() Check if the browser can play the specified audio type.
fastSeek() Specify the playback time in the audio player.
getStartDate() Return a new Date object representing the current timeline offset.
load() Reload the audio element.
play() Start playing the audio.
pause() Pause the currently playing audio.

Standard properties and events

Audio object supports standardsAttributesandEvents.

Related pages

HTML Tutorial:HTML5 Audio

HTML Reference Manual:HTML <audio> tag