HTML DOM Audio object
Audio object
The Audio object is new in HTML5.
The Audio object represents HTML
Access the Audio object
You can use getElementById() to access it
var x = document.getElementById("myAudio");
Try it
Create an Audio object
You can use the document.createElement() method to create
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 to play the audio immediately after loading is complete |
| buffered | Returns a TimeRanges object representing the buffered portion of the audio |
| controller | Returns a MediaController object representing the current media controller of the audio |
| controls | Sets or returns whether the audio displays controls (such as 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 replay at the end |
| mediaGroup | Sets or returns the group the audio belongs to (used to connect 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 playback speed of the audio |
| played | Returns a TimeRanges object representing the played portion of the audio |
| preload | Sets or returns whether the audio should load after the page loads |
| readyState | Returns the current readiness state of the audio |
| seekable | Returns a TimeRanges object representing the seekable portion of the audio |
| seeking | Returns whether the user is seeking 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() | Adds a new text track to the audio |
| canPlayType() | Checks whether the browser can play the specified audio type |
| fastSeek() | Specifies the playback time in the audio player. |
| getStartDate() | Returns a new Date object representing the current timeline offset |
| load() | Reloads the audio element |
| play() | Starts playing the audio |
| pause() | Pauses the currently playing audio |
Standard properties and events
The Canvas object also supports standard property and Events.
Related Articles
HTML Tutorial: HTML5 audio
HTML Reference Manual: HTML
HTML Audio/Video DOM Reference Manual: HTML Audio/Video