HTML DOM Audio object

Audio object

Audio object New in HTML5. image.png

Audio objects represent HTML <audio> elements.

Access Audio objects

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

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

 Try It! 

Create Audio object

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

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

Try It! 

Audio Object Properties

audiotracksReturns an AudioTrackList object representing the available audio tracks
autoplaySets or returns whether to play audio immediately after loading
bufferedReturns a TimeRanges object representing the buffered portion of the audio
controllerReturns a MediaController object representing the audio's current media controller
controlsSets or returns whether the audio displays controls (such as play/pause, etc.)
crossOriginSets or returns CORS settings for audio
currentSrcReturns the URL of the current audio
currentTimeSets or returns the current playback position in the audio (in seconds)
defaultMutedSets or returns whether the audio is muted by default
defaultPlaybackRateSets or returns the default playback speed for audio
durationReturns the length of the current audio in seconds
endedReturns whether the audio playback has ended
errorReturns a MediaError object representing the audio error status
loopSets or returns whether the audio should be replayed at the end
mediaGroupSets or returns the group to which the audio belongs (for connecting multiple audio elements)
mutedSets or returns whether the audio is muted
networkStateReturns the current network state of the audio
pausedSets or returns whether the audio is paused
playbackRateSets or returns the speed of audio playback
playedReturns a TimeRanges object representing the played portion of the audio
preloadSets or returns whether the audio should be loaded after the page loads
readyStateReturns the current ready state of the audio
seekableReturns a TimeRanges object representing the addressable portion of the audio
seekingReturns whether the user is looking in the audio
srcSets or returns the current source of the audio element
textTracksReturns a TextTrackList object representing the available text tracks
volumeSets or returns the volume of the audio

Audio object methods

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

Standard Properties and Events

Canvas objects also support standard properties and events .

Related articles

HTML tutorial: HTML5 audio

HTML Reference Manual: HTML <audio> Tag

HTML Audio/Video DOM Reference Manual: HTML Audio/Video