aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/mediasource/duration
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/mediasource/duration
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/api/mediasource/duration')
-rw-r--r--files/zh-cn/web/api/mediasource/duration/index.html94
1 files changed, 94 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/mediasource/duration/index.html b/files/zh-cn/web/api/mediasource/duration/index.html
new file mode 100644
index 0000000000..400256f465
--- /dev/null
+++ b/files/zh-cn/web/api/mediasource/duration/index.html
@@ -0,0 +1,94 @@
+---
+title: MediaSource.duration
+slug: Web/API/MediaSource/duration
+translation_of: Web/API/MediaSource/duration
+---
+<div>{{APIRef("Media Source Extensions")}}{{SeeCompatTable}}</div>
+
+<p>{{domxref("MediaSource")}} 接口的属性 <code><strong>duration</strong></code> 用来获取或者设置当前媒体展示的时长.</p>
+
+<h2 id="语法">语法</h2>
+
+<pre class="brush: js">mediaSource.duration = 5.5; // 5.5 seconds
+
+var myDuration = mediaSource.duration;</pre>
+
+<h3 id="值">值</h3>
+
+<p>以秒为单位的 双精度浮点数.</p>
+
+<h3 id="错误">错误</h3>
+
+<p>设置新的值的时候可能会有下面的错误抛出.</p>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">错误</th>
+ <th scope="col">异常</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td><code>InvalidAccessError</code></td>
+ <td>时长尝试设置一个负数, 或者 <code>NaN</code>.</td>
+ </tr>
+ <tr>
+ <td><code>InvalidStateError</code></td>
+ <td>{{domxref("MediaSource.readyState")}} 状态不是 <code>open</code>, 或者 一个或多个 {{domxref("SourceBuffer")}} 对象在 {{domxref("MediaSource.sourceBuffers")}} 中被更新  (例如. 该 {{domxref("SourceBuffer.updating")}}属性 为 <code>true</code>.)</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="例子">例子</h2>
+
+<p>下面的代码片段取自 Nick Desaulniers写的简单例子 (想进一步了解 <a href="http://nickdesaulniers.github.io/netfix/demo/bufferAll.html">查看完整例子</a>, 或者 <a href="https://github.com/nickdesaulniers/netfix/blob/gh-pages/demo/bufferAll.html">下载源代码</a> .)</p>
+
+<pre class="brush: js language-js"><code class="language-js"><span class="keyword token">function</span> sourceOpen <span class="punctuation token">(</span>_<span class="punctuation token">)</span> <span class="punctuation token">{</span>
+ <span class="comment token"> //console.log(this.readyState); // open
+</span> <span class="keyword token">var</span> mediaSource <span class="operator token">=</span> <span class="keyword token">this</span><span class="punctuation token">;</span>
+ <span class="keyword token">var</span> sourceBuffer <span class="operator token">=</span> mediaSource<span class="punctuation token">.</span><span class="function token">addSourceBuffer<span class="punctuation token">(</span></span>mimeCodec<span class="punctuation token">)</span><span class="punctuation token">;</span>
+ <span class="function token">fetchAB<span class="punctuation token">(</span></span>assetURL<span class="punctuation token">,</span> <span class="keyword token">function</span> <span class="punctuation token">(</span>buf<span class="punctuation token">)</span> <span class="punctuation token">{</span>
+ sourceBuffer<span class="punctuation token">.</span><span class="function token">addEventListener<span class="punctuation token">(</span></span><span class="string token">'updateend'</span><span class="punctuation token">,</span> <span class="keyword token">function</span> <span class="punctuation token">(</span>_<span class="punctuation token">)</span> <span class="punctuation token">{</span>
+ mediaSource<span class="punctuation token">.</span><span class="function token">endOfStream<span class="punctuation token">(</span></span><span class="punctuation token">)</span><span class="punctuation token">;
+ mediaSource.duration = 120;</span>
+ video<span class="punctuation token">.</span><span class="function token">play<span class="punctuation token">(</span></span><span class="punctuation token">)</span><span class="punctuation token">;</span>
+ <span class="comment token"> //console.log(mediaSource.readyState); // ended
+</span> <span class="punctuation token">}</span><span class="punctuation token">)</span><span class="punctuation token">;</span>
+ sourceBuffer<span class="punctuation token">.</span><span class="function token">appendBuffer<span class="punctuation token">(</span></span>buf<span class="punctuation token">)</span><span class="punctuation token">;</span>
+ <span class="punctuation token">}</span><span class="punctuation token">)</span><span class="punctuation token">;</span>
+<span class="punctuation token">}</span><span class="punctuation token">;
+
+...</span></code></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('Media Source Extensions', '#widl-MediaSource-duration', 'duration')}}</td>
+ <td>{{Spec2('Media Source Extensions')}}</td>
+ <td>Initial definition.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+<div>
+
+
+<p>{{Compat("api.MediaSource.duration")}}</p>
+</div>
+
+<h2 id="相关链接">相关链接</h2>
+
+<ul>
+ <li>{{domxref("SourceBuffer")}}</li>
+ <li>{{domxref("SourceBufferList")}}</li>
+</ul>