HTMLMediaElement: load() method
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
TheHTMLMediaElement methodload() resets the media element to its initial state andbegins the process of selecting a media source and loading the media in preparationfor playback to begin at the beginning.
The amount of media data that isprefetched is determined by the value of the element'spreload attribute.
This method is generally only useful when you've made dynamic changes to the set ofsources available for the media element, either by changing the element'ssrc attribute or by adding or removing<source> elements nested within the media element itself.load() will reset the element and rescan the available sources, therebycausing the changes to take effect.
In this article
Syntax
load()Parameters
None.
Return value
None (undefined).
Usage notes
Callingload() aborts all ongoing operations involving this media element,then begins the process of selecting and loading an appropriate media resource given theoptions specified in the<audio> or<video> elementand itssrc attribute or child<source>element(s). This is described in more detail in theHTML video and audio page.
The process of aborting any ongoing activities will cause any outstandingPromises returned byplay() beingfulfilled or rejected as appropriate based on their status before the loading of newmedia can begin. Pending play promises are aborted with an"AbortError"DOMException.
Appropriate events will be sent to the media element itself as the load processproceeds:
- If the element is already in the process of loading media, that load process isaborted and the
abortevent is sent. - If the element has already been initialized with media, the
emptiedevent is sent. - If resetting the playback position to the beginning of the media actually changesthe playback position (that is, it was not already at the beginning), a
timeupdateevent is sent. - Once media has been selected and loading is ready to begin, the
loadstartevent is delivered. - From this point onward, events are sent just like any media load.
Examples
This example finds a<video> element in the document and resets it bycallingload().
const mediaElem = document.querySelector("video");mediaElem.load();Specifications
| Specification |
|---|
| HTML> # dom-media-load-dev> |