SourceBuffer.mode
Experimental
这是一个实验中的功能
此功能某些浏览器尚在开发中,请参考浏览器兼容性表格以得到在不同浏览器中适合使用的前缀。由于该功能对应的标准文档可能被重新修订,所以在未来版本的浏览器中该功能的语法和行为可能随之改变。
SourceBuffer
接口的 mode
属性用来控制媒体片段添加到SourceBuffer
时的顺序是可以任意的还是有严格顺序的。
两个可用的值:
segments
: 媒体片段的时间戳决定段的播放顺序。这些片段可以按任意顺序添加到sourcebuffer。sequence
: 媒体片段添加到sourcebuffer的顺序决定了它们的播放顺序。片段上的时间戳为遵守此顺序自动生成。
moder的值最初是在使用mediasource.addsourcebuffer()创建sourcebuffer时设置的。如果媒体片段上已经存在时间戳,则该值将设置为segments
;如果没有,则该值将设置为sequence
.
如果mode初始值为sequence想要改为segments则会引发错误, 必须以sequence
模式维护现有段顺序。但是,可以将值从segments模式
改为sequence模式
。它意味着播放顺序将被固定,并会生成新的时间戳。
当 sourceBuffer 正在处理时mode的值无法改变,如 appendBuffer()
或 remove()
(en-US) .
Syntax
var myMode = sourceBuffer.mode;
sourceBuffer.mode = 'sequence';
Value
A DOMString
.
Errors
The following errors may be thrown when setting a new value for this property.
Error | Explanation |
---|---|
InvalidAccessError |
An attempt was made to set the value to segments when the initial value is sequence . |
InvalidStateError |
The SourceBuffer object is being updated (i.e. its SourceBuffer.updating (en-US) property is currently true ), the last media segment appended to this SourceBuffer is incomplete, or this SourceBuffer has been removed from the MediaSource . |
Example
此代码段是将sourcebuffer的模式设置为“sequence”(如果当前设置为“segments”),假如原先的播放顺序为segments.
var curMode = sourceBuffer.mode;
if (curMode == 'segments') {
sourceBuffer.mode = 'sequence';
}
Specifications
Specification | Status | Comment |
---|---|---|
Media Source Extensions mode |
Recommendation | Initial definition. |
Browser compatibility
BCD tables only load in the browser