blob: eb674466d950415b60db98a870f9ab3aeb6dfc28 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
---
title: HTMLMediaElement.load()
slug: Web/API/HTMLMediaElement/load
translation_of: Web/API/HTMLMediaElement/load
---
<div>{{APIRef("HTML DOM")}}</div>
<p><span class="seoSummary"> <code><strong>load()</strong></code> 方法重置媒体成初始化状态,选择一个播放源, 为载入媒体重新播放做准备。</span> 媒体预播放的信息是由 <span class="seoSummary"><code><strong>preload</strong></code></span> 这个参数决定的。</p>
<p>此方法只在对媒体做动态更改时管用,要么更改<code>src</code>属性,要么添加或删除<code>source</code> 。 <code>load()</code> 将会重置元素重新扫描可用的源,从而让改动生效。</p>
<h2 id="语法">语法</h2>
<pre class="syntaxbox"><em>mediaElement</em>.load();</pre>
<h3 id="参数">参数</h3>
<p>None.</p>
<h3 id="返回值">返回值</h3>
<p><code>undefined</code>.</p>
<h2 id="用法">用法</h2>
<p>调用 <code>load()</code> 会使媒体上所有正在进行的操作中止,然后根据 <code>audio</code> 或者 <code>video</code> 元素的 <code>src</code> 或者 <code>source</code> 属性里寻找合适的播放源并重新加载媒体内容。 更多查看 <a href="https://wiki.developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Video_and_audio_content#Supporting_multiple_formats" title="And that's a wrap; we hope you had fun playing with video and audio in web pages! In the next article, we'll look at other ways of embedding content on the Web, using technologies like <iframe> and <object>.">Supporting multiple formats</a> 和 <a href="https://wiki.developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Video_and_audio_content" title="And that's a wrap; we hope you had fun playing with video and audio in web pages! In the next article, we'll look at other ways of embedding content on the Web, using technologies like <iframe> and <object>.">Video and audio content</a> 。</p>
<p>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 <code>"AbortError"</code> {{domxref("DOMException")}}.</p>
<p>在load过程中 合适的事件会发生并通知给媒体本身,包括:</p>
<ul>
<li>如果已经是 <code>load</code> 过了,则 <code>abort</code> 事件发送给媒体。</li>
<li>If the element has already been initialized with media, the <strong>{{event("emptied")}}</strong> event is sent.</li>
<li>如果重置播放位置到开始,通常指修改播放位置,<strong>timeupdate</strong> 事件触发。</li>
<li>当已经选择了源并且已经准备加载内容了,<strong>loadstart</strong> 事件触发。</li>
<li>之前的几点,媒体加载并且事件已经送达</li>
</ul>
<h2 id="例子">例子</h2>
<p>例子中有一个 {{HTMLElement("video")}} 元素然后重置它 <code>load()</code>.</p>
<pre class="brush: js">var mediaElem = document.querySelector("video");
mediaElem.load();
</pre>
<h2 id="说明">说明</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
<th scope="col">Comment</th>
</tr>
<tr>
<td>{{SpecName('HTML WHATWG', "media.html#dom-media-load", "HTMLMediaElement.load()")}}</td>
<td>{{Spec2('HTML WHATWG')}}</td>
<td>Initial definition.</td>
</tr>
<tr>
<td>{{SpecName('HTML5 W3C', "semantics-embedded-content.html#dom-htmlmediaelement-load", "HTMLMediaElement.load()")}}</td>
<td>{{Spec2('HTML5 W3C')}}</td>
<td>Initial definition.</td>
</tr>
</tbody>
</table>
<h2 id="浏览器兼容性">浏览器兼容性</h2>
<p>{{Compat("api.HTMLMediaElement.load")}}</p>
|