SourceBuffer.mode

这篇翻译不完整。请帮忙从英语翻译这篇文章

这是一个实验中的功能
此功能某些浏览器尚在开发中,请参考浏览器兼容性表格以得到在不同浏览器中适合使用的前缀。由于该功能对应的标准文档可能被重新修订,所以在未来版本的浏览器中该功能的语法和行为可能随之改变。

SourceBuffer 接口的 mode 属性用来控制媒体片段添加到SourceBuffer 时的顺序是可以任意的还是有严格顺序的。

两个可用的值:

  • segments: 媒体片段的时间戳决定段的播放顺序。这些片段可以按任意顺序添加到sourcebuffer。
  • sequence: 媒体片段添加到sourcebuffer的顺序决定了它们的播放顺序。片段上的时间戳为遵守此顺序自动生成。

moder的值最初是在使用mediasource.addsourcebuffer()创建sourcebuffer时设置的。如果媒体片段上已经存在时间戳,则该值将设置为segments;如果没有,则该值将设置为sequence.

如果mode初始值为sequence想要改为segments则会引发错误, 必须以sequence模式维护现有段顺序。但是,可以将值从segments模式改为sequence模式。它意味着播放顺序将被固定,并会生成新的时间戳。

当 sourceBuffer 正在处理时mode的值无法改变,如 appendBuffer() 或 remove() .

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 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

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
modeChrome Full support 23Edge Full support 12Firefox Full support 42
Full support 42
No support 25 — 42
Notes Disabled
Notes Limited support to a whitelist of sites, for example YouTube, Netflix, and other popular streaming sites. The whitelist was removed when Media Source Extensions was enabled by default in Firefox 42.
Disabled From version 25 until version 42 (exclusive): this feature is behind the media.mediasource.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
IE Full support 11
Notes
Full support 11
Notes
Notes Only works on Windows 8+.
Opera Full support 15Safari Full support 8WebView Android Full support 4.4.3Chrome Android Full support 33Firefox Android No support NoOpera Android Full support 14Safari iOS No support NoSamsung Internet Android ?

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
See implementation notes.
See implementation notes.
User must explicitly enable this feature.
User must explicitly enable this feature.

See also

文档标签和贡献者

此页面的贡献者: wzwmzm
最后编辑者: wzwmzm,