HTMLMediaElement.load() - Web APIs 编辑

The HTMLMediaElement method load() resets the media element to its initial state and begins the process of selecting a media source and loading the media in preparation for playback to begin at the beginning. The amount of media data that is prefetched is determined by the value of the element's preload attribute.

This method is generally only useful when you've made dynamic changes to the set of sources available for the media element, either by changing the element's src attribute or by adding or removing <source> elements nested within the media element itself. load() will reset the element and rescan the available sources, thereby causing the changes to take effect.

Syntax

mediaElement.load();

Parameters

None.

Return value

undefined.

Usage notes

Calling load() aborts all ongoing operations involving this media element, then begins the process of selecting and loading an appropriate media resource given the options specified in the <audio> or <video> element and its src attribute or child <source> element(s). This is described in more detail in Supporting multiple formats in Video and audio content.

The process of aborting any ongoing activities will cause any outstanding Promises returned by 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" DOMException.

Appropriate events will be sent to the media element itself as the load process proceeds:

  • If the element is already in the process of loading media, that load process is aborted and the abort event is sent.
  • If the element has already been initialized with media, the emptied event is sent.
  • If resetting the playback position to the beginning of the media actually changes the playback position (that is, it was not already at the beginning), a timeupdate event is sent.
  • Once media has been selected and loading is ready to begin, the loadstart event is delivered.
  • From this point onward, events are sent just like any media load.

Example

This example finds a <video> element in the document and resets it by calling load().

var mediaElem = document.querySelector("video");
mediaElem.load();

Specifications

SpecificationStatusComment
HTML Living Standard
The definition of 'HTMLMediaElement.load()' in that specification.
Living StandardInitial definition.
HTML5
The definition of 'HTMLMediaElement.load()' in that specification.
RecommendationInitial definition.

Browser compatibility

BCD tables only load in the browser

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:95 次

字数:5589

最后编辑:6 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文