<audio>
HTML DOM Audio object
Audio object
Audio object New in HTML5.
Audio objects represent HTML <audio> elements.
Access Audio objects
You can use getElementById() to access the <audio> element:
var x = document.getElementById("myAudio");
Create Audio object
You can create <audio> elements using the document.createElement() method:
var x = document.createElement("AUDIO");
Audio Object Properties
Attribute | Description |
---|---|
audiotracks | Returns an AudioTrackList object representing the available audio tracks |
autoplay | Sets or returns whether to play audio immediately after loading |
buffered | Returns a TimeRanges object representing the buffered portion of the audio |
controller | Returns a MediaController object representing the audio's current media controller |
controls | Sets or returns whether the audio displays controls (such as play/pause, etc.) |
crossOrigin | Sets or returns CORS settings for 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 for audio |
duration | Returns the length of the current audio in seconds |
ended | Returns whether the audio playback has ended |
error | Returns a MediaError object representing the audio error status |
loop | Sets or returns whether the audio should be replayed at the end |
mediaGroup | Sets or returns the group to which the audio belongs (for connecting 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 |
playbackRate | Sets or returns the speed of audio playback |
played | Returns a TimeRanges object representing the played portion of the audio |
preload | Sets or returns whether the audio should be loaded after the page loads |
readyState | Returns the current ready state of the audio |
seekable | Returns a TimeRanges object representing the addressable portion of the audio |
seeking | Returns whether the user is looking in the audio |
src | Sets or returns the current source of the audio element |
textTracks | Returns a TextTrackList object representing the available text tracks |
volume | Sets or returns the volume of the audio |
Audio object methods
Method | Description |
---|---|
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