From 220356567656026d9392a98bffd0ad852899da88 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 | 144 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) diff --git a/index.bs b/index.bs index ccc9740..5f9e9bc 100644 --- a/index.bs +++ b/index.bs @@ -104,6 +104,7 @@ urlPrefix: https://www.w3.org/TR/appmanifest/; spec: appmanifest text: image object; url: #dfn-image-object urlPrefix: https://heycam.github.io/webidl/ type: exception + text: DataError text: TypeError urlPrefix: https://tc39.github.io/ecma262/#sec-object.; type: dfn text: freeze @@ -618,6 +619,69 @@ 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. +

+ +

+ 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 current playback position in seconds is computed in the following + way: +

+

+ +
+

The {{MediaSession}} interface

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

+

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

+

+

The {{MediaMetadata}} interface

@@ -1016,6 +1105,34 @@ 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 unrestricted double duration;
+  double playbackRate = 0.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, negative to represent backwards playback or zero to represent media that +is paused. + +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 +1303,33 @@ 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.setPositionState({
+      duration: 60,
+      playbackRate: 1,
+      position: 0
+    });
+
+    // Media is paused 30 seconds in.
+    navigator.mediaSession.setPositionState({
+      duration: 60,
+      playbackRate: 0,
+      position: 30
+    });
+
+    // Media is reset.
+    navigator.mediaSession.setPositionState(null);
+  
+
+

Acknowledgments

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