blob: 369280a54ed7939f3922b20fc5864d58d11d32f0 (
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
|
---
title: SourceBuffer.mode
slug: Web/API/SourceBuffer/mode
translation_of: Web/API/SourceBuffer/mode
---
<div>{{APIRef("Media Source Extensions")}}{{SeeCompatTable}}</div>
<p>{{domxref("SourceBuffer")}} 接口的 <code><strong>mode</strong></code> 属性用来控制媒体片段添加到<code>SourceBuffer</code> 时的顺序是可以任意的还是有严格顺序的。</p>
<p>两个可用的值:</p>
<ul>
<li><code>segments</code>: 媒体片段的时间戳决定段的播放顺序。这些片段可以按任意顺序添加到sourcebuffer。</li>
<li><code>sequence</code>: 媒体片段添加到sourcebuffer的顺序决定了它们的播放顺序。片段上的时间戳为遵守此顺序自动生成。</li>
</ul>
<p>moder的值最初是在使用mediasource.addsourcebuffer()创建sourcebuffer时设置的。如果媒体片段上已经存在时间戳,则该值将设置为<code>segments</code>;如果没有,则该值将设置为<code>sequence</code>.</p>
<p>如果mode初始值为sequence想要改为segments则会引发错误, 必须以<code>sequence</code>模式维护现有段顺序。但是,可以将值从<code>segments模式</code>改为<code>sequence模式</code>。它意味着播放顺序将被固定,并会生成新的时间戳。</p>
<p>当 sourceBuffer 正在处理时mode的值无法改变,如 {{domxref("SourceBuffer.appendBuffer","appendBuffer()")}} 或 {{domxref("SourceBuffer.remove","remove()")}} .</p>
<h2 id="Syntax">Syntax</h2>
<pre class="brush: js">var myMode = sourceBuffer.mode;
sourceBuffer.mode = 'sequence';
</pre>
<h3 id="Value">Value</h3>
<p>A {{domxref("DOMString")}}.</p>
<h3 id="Errors">Errors</h3>
<p>The following errors may be thrown when setting a new value for this property.</p>
<table class="standard-table">
<thead>
<tr>
<th scope="col">Error</th>
<th scope="col">Explanation</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>InvalidAccessError</code></td>
<td>An attempt was made to set the value to <code>segments</code> when the initial value is <code>sequence</code>.</td>
</tr>
<tr>
<td><code>InvalidStateError</code></td>
<td>The {{domxref("SourceBuffer")}} object is being updated (i.e. its {{domxref("SourceBuffer.updating")}} property is currently <code>true</code>), the last media segment appended to <code>this </code>SourceBuffer is incomplete, or this <code>SourceBuffer</code> has been removed from the {{domxref("MediaSource")}}.</td>
</tr>
</tbody>
</table>
<h2 id="Example">Example</h2>
<p>此代码段是将sourcebuffer的模式设置为“sequence”(如果当前设置为“segments”),假如原先的播放顺序为segments.</p>
<pre class="brush: js">var curMode = sourceBuffer.mode;
if (curMode == 'segments') {
sourceBuffer.mode = 'sequence';
}</pre>
<h2 id="Specifications">Specifications</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-SourceBuffer-mode', 'mode')}}</td>
<td>{{Spec2('Media Source Extensions')}}</td>
<td>Initial definition.</td>
</tr>
</tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<div>
<p>{{Compat("api.SourceBuffer.mode")}}</p>
</div>
<h2 id="See_also">See also</h2>
<ul>
<li>{{domxref("MediaSource")}}</li>
<li>{{domxref("SourceBufferList")}}</li>
</ul>
|