aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/htmlmediaelement/networkstate/index.html
blob: 09164c8b356ac0e51f11c5ac61ebcf1da9531623 (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
---
title: HTMLMediaElement.networkState
slug: Web/API/HTMLMediaElement/networkState
tags:
  - API
  - HTML DOM
  - Web
  - 只读
  - 属性
translation_of: Web/API/HTMLMediaElement/networkState
---
<div>{{APIRef("HTML DOM")}}</div>

<p><span class="seoSummary"> <strong><code>HTMLMediaElement.networkState</code></strong> 属性表示在网络上获取媒体的当前状态。</span></p>

<h2 id="Syntax" name="Syntax">语法</h2>

<pre class="syntaxbox">var networkState = audioOrVideo.networkState;</pre>

<h3 id="取值">取值</h3>

<p>一个 <code>unsigned short</code>。可能的值包括:</p>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">常量</th>
   <th scope="col"> 值 </th>
   <th scope="col">描述</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td><code>NETWORK_EMPTY</code></td>
   <td>0</td>
   <td>还没有数据。并且 <code>readyState</code> 的值是 <code>HAVE_NOTHING</code></td>
  </tr>
  <tr>
   <td><code>NETWORK_IDLE</code></td>
   <td>1</td>
   <td>HTMLMediaElement 是有效的并且已经选择了一个资源,,但是还没有使用网络。</td>
  </tr>
  <tr>
   <td><code>NETWORK_LOADING</code></td>
   <td>2</td>
   <td>浏览器正在下载 HTMLMediaElement 数据。</td>
  </tr>
  <tr>
   <td><code>NETWORK_NO_SOURCE</code></td>
   <td>3</td>
   <td>没有找到 HTMLMediaElement src。</td>
  </tr>
 </tbody>
</table>

<h2 id="例子">例子</h2>

<p>这个例子监听audio元素以开始播放,然后检查是否仍然在加载数据。</p>

<pre class="brush: html">&lt;audio id="example" preload="auto"&gt;
 &lt;source src="sound.ogg" type="audio/ogg" /&gt;
&lt;/audio&gt;

</pre>

<pre class="brush: js">var obj = document.getElementById('example');

obj.addEventListener('playing', function() {

  if (obj.networkState === 2) {
    // Still loading...
  }

});
</pre>

<h2 id="规范">规范</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">规范</th>
   <th scope="col">状态</th>
   <th scope="col">注释</th>
  </tr>
  <tr>
   <td>{{SpecName('HTML WHATWG', "the-video-element.html#htmlmediaelement", "HTMLMediaElement.networkState")}}</td>
   <td>{{Spec2('HTML WHATWG')}}</td>
   <td>未对 {{SpecName('HTML5 W3C')}} 更改</td>
  </tr>
  <tr>
   <td>{{SpecName('HTML5 W3C', "embedded-content-0.html#htmlmediaelement", "HTMLMediaElement.networkState")}}</td>
   <td>{{Spec2('HTML5 W3C')}}</td>
   <td>初始定义。</td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器兼容性">浏览器兼容性</h2>

<p>{{ CompatibilityTable() }}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Edge</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatGeckoDesktop("1.9.1")}} [1]</td>
   <td>{{CompatIE("9")}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Edge</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>Firefox OS (Gecko)</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<p>[1]  <code>NETWORK_LOADED</code> 已被移除以与Gecko 2.0的HTML规范一致。{{geckoRelease(2)}}</p>

<h2 id="See_Also" name="See_Also">另见</h2>

<ul>
 <li>定义它的接口, {{domxref("HTMLMediaElement")}}.</li>
</ul>