MediaSource: duration プロパティ
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
duration は MediaSource インターフェイスのプロパティで、現在表示されているメディアの期間(長さ)を取得および設定します。
値
double 型。 秒単位の値が必要です。
例外
このプロパティに新しい値を設定すると、次の例外が発生する場合があります。
InvalidAccessErrorDOMException-
負の値または
NaNである再生時間の値を設定しようとした場合に発生します。 InvalidStateErrorDOMException-
MediaSource.readyStateがopenに等しくないか、MediaSource.sourceBuffers内のSourceBufferオブジェクトが 1 つ以上更新されている(つまり、SourceBuffer.updatingプロパティがtrueである)場合に発生します。
例
次のスニペットは、Nick Desaulniers によって書かれた簡単な例に基づいています(ライブで完全なデモを見るか、ソースをダウンロードしてさらに調査してください)。ここでは定義されていませんが、関数 getMediaSource() は MediaSource を返します。
js
const mediaSource = getMediaSource();
function sourceOpen() {
console.log(this.readyState); // open
const sourceBuffer = mediaSource.addSourceBuffer(mimeCodec);
fetchAB(assetURL, (buf) => {
sourceBuffer.addEventListener("updateend", () => {
mediaSource.endOfStream();
mediaSource.duration = 120;
video.play();
console.log(mediaSource.readyState); // ended
});
sourceBuffer.appendBuffer(buf);
});
}
// …
仕様書
| Specification |
|---|
| Media Source Extensions™> # dom-mediasource-duration> |
ブラウザーの互換性
Loading…