MediaSource: duration プロパティ

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

durationMediaSource インターフェイスのプロパティで、現在表示されているメディアの期間(長さ)を取得および設定します。

double 型。 秒単位の値が必要です。

例外

このプロパティに新しい値を設定すると、次の例外が発生する場合があります。

InvalidAccessError DOMException

負の値または NaN である再生時間の値を設定しようとした場合に発生します。

InvalidStateError DOMException

MediaSource.readyStateopen に等しくないか、 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

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
duration

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
No support
No support

関連情報