YouTip LogoYouTip

Dom Obj Audio

HTML DOM Audio Object

HTML DOM Audio Object

Audio Object

The Audio object is new in HTML5.

The Audio object represents an HTML <audio> element.

Accessing the Audio Object

You can use getElementById() to access the <audio> element:

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

Try it

Creating an Audio Object

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

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

Try it

Audio Object Properties

Property Description
audioTracks Returns an AudioTrackList object representing the available audio tracks
autoplay Sets or returns whether the audio should start playing as soon as it is loaded
buffered Returns a TimeRanges object representing the buffered parts of the audio
controller Returns a MediaController object representing the current media controller of the audio
controls Sets or returns whether the audio should display controls (like play/pause etc.)
crossOrigin Sets or returns the CORS settings of the audio
currentSrc Returns the URL of the current audio
currentTime Sets or returns the current playback position in the audio (in seconds)
defaultMuted Sets or returns whether the audio is muted by default
defaultPlaybackRate Sets or returns the default playback speed of the audio
duration Returns the length of the current audio (in seconds)
ended Returns whether the playback of the audio has ended
error Returns a MediaError object representing the error state of the audio
loop Sets or returns whether the audio should start over again when finished
mediaGroup Sets or returns the group the audio belongs to (used to link multiple audio elements)
muted Sets or returns whether the audio is muted
networkState Returns the current network state of the audio
paused Sets or returns whether the audio is paused
← Ruby IntroMet Audio Pause β†’