这是
实验性技术
检查
浏览器兼容性表格
要小心谨慎在生产中使用这之前。
duration
特性为
MediaSource
interface gets and sets the duration of the current media being presented.
mediaSource.duration = 5.5; // 5.5 seconds var myDuration = mediaSource.duration;
A double. A value in seconds is expected.
The following exceptions may be thrown when setting a new value for this property.
| 异常 | 解释 |
|---|---|
InvalidAccessError
|
An attempt was made to set a duration value that was negative, or
NaN
.
|
InvalidStateError
|
MediaSource.readyState
不等于
open
, or one or more of the
SourceBuffer
对象在
MediaSource.sourceBuffers
are being updated (i.e. their
SourceBuffer.updating
特性为
true
)。
|
The following snippet is based on a simple example written by Nick Desaulniers ( view the full demo live ,或 download the source for further investigation.)
function sourceOpen (_) {
//console.log(this.readyState); // open
var mediaSource = this;
var sourceBuffer = mediaSource.addSourceBuffer(mimeCodec);
fetchAB(assetURL, function (buf) {
sourceBuffer.addEventListener('updateend', function (_) {
mediaSource.endOfStream();
mediaSource.duration = 120;
video.play();
//console.log(mediaSource.readyState); // ended
});
sourceBuffer.appendBuffer(buf);
});
};
...
| 规范 | 状态 | 注释 |
|---|---|---|
|
媒体源扩展
The definition of 'duration' in that specification. |
推荐 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
duration
|
Chrome 23 | Edge 12 |
Firefox
42
|
IE 11 | Opera 15 | Safari 8 | WebView Android 4.4.3 | Chrome Android 25 | Firefox Android 41 | Opera Android 14 | Safari iOS 不支持 No | Samsung Internet Android 1.5 |
完整支持
不支持
实验。期望将来行为有所改变。
见实现注意事项。
用户必须明确启用此特征。
MediaSource
activeSourceBuffers
duration
readyState
sourceBuffers