--- title: HTMLMediaElement.load() slug: Web/API/HTMLMediaElement/load translation_of: Web/API/HTMLMediaElement/load ---
load() 方法重置媒体成初始化状态,选择一个播放源, 为载入媒体重新播放做准备。 媒体预播放的信息是由 preload 这个参数决定的。
此方法只在对媒体做动态更改时管用,要么更改src属性,要么添加或删除source 。 load() 将会重置元素重新扫描可用的源,从而让改动生效。
mediaElement.load();
None.
undefined.
调用 load() 会使媒体上所有正在进行的操作中止,然后根据 audio 或者 video 元素的 src 或者 source 属性里寻找合适的播放源并重新加载媒体内容。 更多查看 Supporting multiple formats 和 Video and audio content 。
The process of aborting any ongoing activities will cause any outstanding {{jsxref("Promise")}}s returned by {{domxref("HTMLMediaElement.play", "play()")}} being resolved or rejected as appropriate based on their status before the loading of new media can begin. Pending play promises are aborted with an "AbortError" {{domxref("DOMException")}}.
在load过程中 合适的事件会发生并通知给媒体本身,包括:
load 过了,则 abort 事件发送给媒体。例子中有一个 {{HTMLElement("video")}} 元素然后重置它 load().
var mediaElem = document.querySelector("video");
mediaElem.load();
| Specification | Status | Comment |
|---|---|---|
| {{SpecName('HTML WHATWG', "media.html#dom-media-load", "HTMLMediaElement.load()")}} | {{Spec2('HTML WHATWG')}} | Initial definition. |
| {{SpecName('HTML5 W3C', "semantics-embedded-content.html#dom-htmlmediaelement-load", "HTMLMediaElement.load()")}} | {{Spec2('HTML5 W3C')}} | Initial definition. |
{{Compat("api.HTMLMediaElement.load")}}