MediaPositionState dictionary's duration property is used when calling the MediaSession 方法 setPositionState() to provide the 用户代理 with the overall total duration in seconds of the media currently being performed. This information can then, in turn, be used by the user agent to provide a user interface which displays media playback information to the viewer.

For example, a browser might use this information along with the 位置 特性和 navigator.mediaSession.playbackState , as well as the session's metadata to provide an integrated common user interface showing the currently playing media as well as standard pause, play, forward, reverse, and other controls.

句法

let positionState = { duration: durationInSeconds };
let durationInSeconds = positionState.duration;
					

A floating-point value indicating the overall duration, in seconds, of the media being performed. This value should always be positive. To indicate media of unknown or indeterminate length, such as an ongoing live stream, specify a value of positive infinity ( Infinity ).

范例

In this example, an app performing a live stream provides information to the browser by preparing a MediaPositionState object and submitting it by calling navigator.mediaSession.setPositionState() .

let positionState = {
  duration: Infinity;
  playbackRate: 1.0;
  position: 0.0;
};
navigator.mediaSession.setPositionState(positionState);
					

规范

规范 状态 注释
Media Session Standard
The definition of 'MediaPositionState.duration' in that specification.
草案 初始定义。

浏览器兼容性

No compatibility data found. Please contribute data for "api.MediaPositionState.duration" (depth: 1) to the MDN 兼容性数据存储库 .

元数据

  • 最后修改:
  1. 媒体会话 API
  2. MediaPositionState
  3. 特性
    1. duration
    2. playbackRate
    3. 位置
  4. Related pages for Media Session API
    1. MediaMetadata
    2. MediaSession