Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML Audio/Video

HTML Audio/Video DOM Reference


HTML Audio/Video DOM Reference

The HTML5 DOM provides

These methods, properties, and events allow you to use JavaScript to manipulate the element.


HTML Audio/Video Methods

Method Description
addTextTrack() Adds a new text track to the audio/video.
canPlayType() Checks whether the browser can play the specified audio/video type.
load() Reloads the audio/video element.
play() Starts playing the audio/video.
pause() Pauses the currently playing audio/video.

HTML Audio/Video Properties

property Description
audioTracks Returns an AudioTrackList object representing the available audio tracks.
autoplay Sets or returns whether the audio/video should start playing as soon as it is loaded.
buffered Returns a TimeRanges object representing the buffered parts of the audio/video.
controller Returns a MediaController object representing the current media controller of the audio/video.
controls Sets or returns whether the audio/video should display controls (such as play/pause).
crossOrigin Sets or returns the CORS setting of the audio/video.
currentSrc Returns the URL of the current audio/video.
currentTime Sets or returns the current playback position in the audio/video (in seconds).
defaultMuted Sets or returns whether the audio/video is muted by default.
defaultPlaybackRate Sets or returns the default playback speed of the audio/video.
duration Returns the length of the current audio/video (in seconds).
ended Returns whether the playback of the audio/video has ended.
error Returns a MediaError object representing the error status of the audio/video.
loop Sets or returns whether the audio/video should start over again when it ends.
mediaGroup Sets or returns the group the audio/video belongs to (used to connect multiple audio/video elements).
muted Sets or returns whether the audio/video is muted.
networkState Returns the current network state of the audio/video.
paused Sets or returns whether the audio/video is paused.
playbackRate Sets or returns the playback speed of the audio/video.
played Returns a TimeRanges object representing the played parts of the audio/video.
preload Sets or returns whether the audio/video should be loaded after the page is loaded.
readyState Returns the current ready state of the audio/video.
seekable Returns a TimeRanges object representing the seekable parts of the audio/video.
seeking Returns whether the user is currently seeking in the audio/video.
src Sets or returns the current source of the audio/video element.
startDate Returns a Date object representing the current time offset.
textTracks Returns a TextTrackList object representing the available text tracks.
videoTracks Returns a VideoTrackList object representing the available video tracks.
volume Sets or returns the volume of the audio/video.

HTML Audio/Video Events

Events Description
abort Fired when the loading of the audio/video has been aborted.
canplay Fired when the browser can start playing the audio/video.
canplaythrough Fired when the browser can play the audio/video without stopping for buffering.
durationchange Fired when the duration of the audio/video has changed.
emptied Fired when the current playlist is empty.
ended Fired when the current playlist has ended.
error Fired when an error occurs during the loading of the audio/video.
loadeddata Fired when the browser has loaded the current frame of the audio/video.
loadedmetadata Fired when the browser has loaded metadata of the audio/video.
loadstart Fired when the browser starts seeking the audio/video.
pause Fired when the audio/video has been paused.
play Fired when the audio/video has started or is no longer paused.
playing Fired when the audio/video is ready after being paused or stalled due to buffering.
progress Fired when the browser is downloading the audio/video.
ratechange Fired when the playback speed of the audio/video has changed.
seeked Fired when the user has moved/jumped to a new position in the audio/video.
seeking Fired when the user starts moving/jumping to a new position in the audio/video.
stalled Fired when the browser tries to fetch media data, but the data is not available.
suspend Fired when the browser deliberately does not fetch media data.
timeupdate Fired when the current playback position has changed.
volumechange Fired when the volume has changed.
waiting Fired when the video stalls because it needs to buffer the next frame.