The MediaPositionState dictionary's duration property is used when calling the MediaSession method setPositionState() to provide the user agent 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 position property and 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;



Specification Status Comment
Media Session Standard
The definition of 'MediaPositionState.duration' in that specification.
Draft Initial definition.

Browser compatibility

No compatibility data found for api.MediaPositionState.duration.
Check for problems with this page or contribute missing data to mdn/browser-compat-data.