HTML DOM AudioObject
Audio Object
The Audio object is new in HTML5..
The Audio object represents an HTML <audio> element.
Access the Audio Object
You can use getElementById() to access the <audio> element:
var x = document.getElementById("myAudio");
Try it Yourself
Create an Audio Object
You can use the document.createElement() method to create an <audio> element:
var x = document.createElement("AUDIO");
Try it Yourself
Audio Object Properties
| Property | Description |
|---|---|
| audioTracks | Returns an AudioTrackList object representing the available audio tracks |
| autoplay | Sets or returns whether the audio should play immediately after loading is complete |
| buffered | Returns a TimeRanges object representing the buffered parts of the audio |
| controller | Returns the MediaController object representing the current media controller of the audio |
| controls | Sets or returns whether the audio shows controls (such as play/pause, etc.) |
| crossOrigin | Sets or returns the CORS setting 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 audio playback has ended |
| error | Returns a MediaError object representing the audio error state |
| loop | Sets or returns whether the audio should replay when it ends |
| mediaGroup | Sets or returns the group to which the audio belongs (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 parts 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 seekable parts of the audio |
| seeking | Returns whether the user is currently 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
Canvas objects also support standardPropertiesandEvents。
Related Articles
HTML Tutorial:HTML5 audio
HTML Reference Manual:HTML <audio> Tag
HTML Audio/Video DOM Reference Manual:HTML Audio/Video
Other Extensions