(In reply to C.M.Chang[:chunmin] from comment #67) > Created attachment 9091931 [details] > Bug 1112032 - P4: Correct MediaSessionActionDetails for seek operations. In the current implementation, I have trouble to meet the following [requirement](https://w3c.github.io/mediasession/#handle-media-session-action): > Run handler with the details parameter set to: > - MediaSessionSeekActionDetails, if action is seekbackward or seekforward. > - MediaSessionSeekToActionDetails, if action is seekto. > - Otherwise, with MediaSessionActionDetails. I cannot read the `MediaSessionSeekToActionDetails.seekTime` from the `MediaSessionActionHandler`'s parameter when the callback/handler is for `seekto` in the javascript test file. The following code demonstrates the problem specifically: ```javascript navigator.mediaSession.setActionHandler("seekto", function(details) { console.log(details.action); // ok, it's "seekto". console.log(details.seekTime); // undefined, but it's a `required` members in MediaSessionSeekToActionDetails }); ``` I guess the reason is because the type of `details` is `MediaSessionActionDetails` instead of `MediaSessionSeekToActionDetails`. I created a test-only function `notifySeekToHandler` to trigger the handler for `seekto`. `notifySeekToHandler` will get a `MediaSessionSeekToActionDetails` object form the caller and pass it directly to the handler. The handler type is `MediaSessionActionHandler`, which is defined as `void(MediaSessionActionDetails details)`. However, the parameter `details` in the handler has no `seekTime` member. I guess the reason is that `details` is a `MediaSessionActionDetails` instead of `MediaSessionSeekToActionDetails`. Not sure if there is a way to make js realize the `details` is actually a `MediaSessionSeekToActionDetails`. ``` enum MediaSessionAction { "play", ... "seekto" }; callback MediaSessionActionHandler = void(MediaSessionActionDetails details); [Exposed=Window] interface MediaSession { ... void setActionHandler(MediaSessionAction action, MediaSessionActionHandler? handler); ... // Test-only function to notify the `seekto` handler [ChromeOnly] void notifySeekToHandler(MediaSessionSeekToActionDetails details); }; dictionary MediaSessionActionDetails { required MediaSessionAction action; }; dictionary MediaSessionSeekToActionDetails : MediaSessionActionDetails { required double seekTime; ... }; ```
Bug 1112032 Comment 68 Edit History
Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.
(In reply to C.M.Chang[:chunmin] from comment #67) > Created attachment 9091931 [details] > Bug 1112032 - P4: Correct MediaSessionActionDetails for seek operations. In the current implementation, I have trouble to meet the following [requirement](https://w3c.github.io/mediasession/#handle-media-session-action): > Run handler with the details parameter set to: > - MediaSessionSeekActionDetails, if action is seekbackward or seekforward. > - MediaSessionSeekToActionDetails, if action is seekto. > - Otherwise, with MediaSessionActionDetails. I cannot read the `MediaSessionSeekToActionDetails.seekTime` from the `MediaSessionActionHandler`'s parameter when the callback/handler is for `seekto` in the javascript test file. The following code demonstrates the problem specifically: ```javascript navigator.mediaSession.setActionHandler("seekto", function(details) { console.log(details.action); // ok, it's "seekto". console.log(details.seekTime); // undefined, but it's a `required` members in MediaSessionSeekToActionDetails }); ``` I guess the reason is because the type of `details` is `MediaSessionActionDetails` instead of `MediaSessionSeekToActionDetails`. I created a test-only function `notifySeekToHandler` to trigger the handler for `seekto`. `notifySeekToHandler` will get a `MediaSessionSeekToActionDetails` object form the caller and pass it directly to the handler. The handler type is `MediaSessionActionHandler`, which is defined as `void(MediaSessionActionDetails details)`. However, the parameter `details` in the handler has no `seekTime` member. I guess the reason is that `details` is a `MediaSessionActionDetails` instead of `MediaSessionSeekToActionDetails`. Not sure if there is a way to make js realize the `details` is actually a `MediaSessionSeekToActionDetails`. ``` [Exposed=Window] partial interface Navigator { [SameObject] readonly attribute MediaSession mediaSession; }; enum MediaSessionAction { "play", ... "seekto" }; callback MediaSessionActionHandler = void(MediaSessionActionDetails details); [Exposed=Window] interface MediaSession { ... void setActionHandler(MediaSessionAction action, MediaSessionActionHandler? handler); ... // Test-only function to notify the `seekto` handler [ChromeOnly] void notifySeekToHandler(MediaSessionSeekToActionDetails details); }; dictionary MediaSessionActionDetails { required MediaSessionAction action; }; dictionary MediaSessionSeekToActionDetails : MediaSessionActionDetails { required double seekTime; ... }; ```
(In reply to C.M.Chang[:chunmin] from comment #67) > Created attachment 9091931 [details] > Bug 1112032 - P4: Correct MediaSessionActionDetails for seek operations. In the current implementation, I have trouble to meet the following [requirement](https://w3c.github.io/mediasession/#handle-media-session-action): > Run handler with the details parameter set to: > - MediaSessionSeekActionDetails, if action is seekbackward or seekforward. > - MediaSessionSeekToActionDetails, if action is seekto. > - Otherwise, with MediaSessionActionDetails. I cannot read the `MediaSessionSeekToActionDetails.seekTime` from the `MediaSessionActionHandler`'s parameter when the callback/handler is for `seekto` in the _javascript_ test file. The following code demonstrates the problem specifically: ```javascript navigator.mediaSession.setActionHandler("seekto", function(details) { console.log(details.action); // ok, it's "seekto". console.log(details.seekTime); // undefined, but it's a `required` members in MediaSessionSeekToActionDetails }); ``` I guess the reason is because the type of `details` is `MediaSessionActionDetails` instead of `MediaSessionSeekToActionDetails`. I created a test-only function `notifySeekToHandler` to trigger the handler for `seekto`. `notifySeekToHandler` will get a `MediaSessionSeekToActionDetails` object form the caller and pass it directly to the handler. The handler type is `MediaSessionActionHandler`, which is defined as `void(MediaSessionActionDetails details)`. However, the parameter `details` in the handler has no `seekTime` member. I guess the reason is that `details` is a `MediaSessionActionDetails` instead of `MediaSessionSeekToActionDetails`. Not sure if there is a way to make _js_ realize the `details` is actually a `MediaSessionSeekToActionDetails`. ``` [Exposed=Window] partial interface Navigator { [SameObject] readonly attribute MediaSession mediaSession; }; enum MediaSessionAction { "play", ... "seekto" }; callback MediaSessionActionHandler = void(MediaSessionActionDetails details); [Exposed=Window] interface MediaSession { ... void setActionHandler(MediaSessionAction action, MediaSessionActionHandler? handler); ... // Test-only function to notify the `seekto` handler [ChromeOnly] void notifySeekToHandler(MediaSessionSeekToActionDetails details); }; dictionary MediaSessionActionDetails { required MediaSessionAction action; }; dictionary MediaSessionSeekToActionDetails : MediaSessionActionDetails { required double seekTime; ... }; ``` In general, I need to figure out how to make the following _javascript_ code works: ```javascript let baseDict = { type: "base" }; let derivedDict = { type: "derived", num: 3.14 }; let foo = new Foo(); foo.setHandler("base",, function(dict) { console.log(dict.type); // "base" console.log(dict.num); // undefined }); foo.setHandler("derived", function(dict) { console.log(dict.type); // "derived" console.log(dict.num); // 3.14 }); runHandlerForBase(baseDict); runHandlerForDerived(derivedDict ); ``` with the following _WebIDL_ interface ```webidl enum Type { "base", "derived" }; dictionary Base { required Type type; }; dictionary Derived : Base { required double num; }; // For "base", the `dict` is `Base` // For "derived", the `dict` is `Derived` callback Handler = void(Base dict); interface Foo { void setHandler(Type type, Handler handler); void runHandlerForBase(Base dict); void runHandlerForDerived(Derived dict); } ```