From bdd6bfc6e0d10149dddc496ff7ead74717c7389e Mon Sep 17 00:00:00 2001 From: Becca Hughes Date: Tue, 12 Mar 2019 10:38:02 -0700 Subject: [PATCH] Add position state to the spec --- index.bs | 159 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 159 insertions(+) diff --git a/index.bs b/index.bs index ccc9740..0300563 100644 --- a/index.bs +++ b/index.bs @@ -618,6 +618,83 @@ conforming IDL fragments, as described in the Web IDL specification. [[!WEBIDL]]

+ +
+

Position State

+ +

+ A user agent MAY display the current playback position and duration + of a media session in the platform UI depending on platform conventions. The + position state is the combination of the following: +

+

+ +

+ The position state is represented by a {{MediaPositionState}} which MUST + always be stored with the last position updated time. This is the + time the position state was last updated in seconds. +

+ +

+ The RECOMMENDED way to determine the position state is to monitor the + media elements whose node document's browsing context is the + browsing context. +

+ +

+ The actual playback rate is a coefficient computed in the following way: +

+

+ +

+ The current playback position in seconds is computed in the following + way: +

+

+ +
+

The {{MediaSession}} interface

@@ -654,6 +731,8 @@ interface MediaSession { attribute MediaSessionPlaybackState playbackState; void setActionHandler(MediaSessionAction action, MediaSessionActionHandler? handler); + + void setPositionState(MediaPositionState? state); }; @@ -748,6 +827,33 @@ interface MediaSession { action and handler on the {{MediaSession}}.

+

+ The setPositionState() method, when + invoked MUST perform the following steps: + +

+

+

The {{MediaMetadata}} interface

@@ -1016,6 +1122,33 @@ used to specify the {{MediaImage}} object's MIME type. It is a hint as to
 the media type of the image. The purpose of this attribute is to allow a user
 agent to ignore images of media types it does not support.
 
+

The {{MediaPositionState}} dictionary

+ +
+
+dictionary MediaPositionState {
+  required double duration;
+  double playbackRate = 1.0;
+  double position = 0.0;
+};
+
+ +The {{MediaPositionState}} dictionary is a representation of the current playback +position associated with a {{MediaSession}} that can be used by user agents to +provide a user interface that displays the current playback position and duration. + +The duration dictionary member +is used to specify the duration in seconds. It should always be positive +and positive infinity can be used to indicate media that is unending. + +The playbackRate dictionary member +is used to specify the playback rate. It can be positive to represent forward +playback or negative to represent backwards playback. It should not be zero. + +The position dictionary member +is used to specify the last reported playback position in seconds. It should +always be positive. +

Examples

This section is non-normative. @@ -1186,6 +1319,32 @@ agent to ignore images of media types it does not support.
+
+ Setting position state: +
+    // Media is loaded, set the duration.
+    navigator.mediaSession.setPositionState({
+      duration: 60
+    });
+
+    // Media starts playing at the beginning.
+    navigator.mediaSession.playbackState = "playing";
+
+    // Media starts playing at 2x 10 seconds in.
+    navigator.mediaSession.setPositionState({
+      duration: 60,
+      playbackRate: 2,
+      position: 10
+    });
+
+    // Media is paused.
+    navigator.mediaSession.playbackState = "paused";
+
+    // Media is reset.
+    navigator.mediaSession.setPositionState(null);
+  
+
+

Acknowledgments

The editors would like to thank Paul Adenot, Jake Archibald, Tab Atkins,