Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MediaSessionActionHandler doesn't work for seek operations #234

Open
ChunMinChang opened this issue Sep 11, 2019 · 1 comment

Comments

@ChunMinChang
Copy link
Contributor

commented Sep 11, 2019

When I tried implementing this spec in Firefox, I had trouble to meet the following requirement:

Run handler with the details parameter set to:

  • MediaSessionSeekActionDetails, if action is seekbackward or seekforward.
  • MediaSessionSeekToActionDetails, if action is seekto.
  • Otherwise, with MediaSessionActionDetails.

Specifically, the following javascript doesn't work

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
});

The problem is because the details is defined as MediaSessionActionDetails instead of MediaSessionSeekToActionDetails.

callback MediaSessionActionHandler = void(MediaSessionActionDetails details);

There's no virtual function table in dictionaries, so the javascript has no idea the details is actually a MediaSessionSeekToActionDetails.

See more details here.

@ChunMinChang

This comment has been minimized.

Copy link
Contributor Author

commented Sep 11, 2019

There are three possible workarounds I could think for now:

  1. Define MediaSessionActionHandler to void(Object details)
  2. Use a single MediaSessionActionDetails containing optional members for seek operations
  3. Use specific setActionHandlers for seek operations

1. Define MediaSessionActionHandler to void(Object details)

Accessing Object directly is likely to cause security issues because JS objects are highly configurable. However, the details is never used as an input argument. It's created in the browser itself so it might be ok to do so.

2. Use a single MediaSessionActionDetails containing optional members for seek operations

By merging MediaSessionSeekActionDetails and MediaSessionSeekToActionDetails into MediaSessionActionDetails, details.seekTime becomes a valid member for MediaSessionActionHandler

dictionary MediaSessionActionDetails {
  required MediaSessionAction action;
  double seekOffset; // optional
  double seekTime; // optional
  bool fastSeek; // optional
};

However, it requires some additional statements in the spec like:

  • seekTime MUST be set when it's for seekto's action handler
  • seekOffset and seekTime MAY be set when it's for the action handlers of seekbackward or seekforward
  • ...

3. Use specific setActionHandlers for seek operations

For example,the following are specific setActionHandler and ActionHandler for seekbackward, seekforward,

callback MediaSessionSeekActionHandler = void(MediaSessionSeekActionDetails details);

void setSeekActionHandler(MediaSessionAction action, MediaSessionSeekActionHandler? handler);

By defining above interface, the javascript side can know the type of the details exactly. However, it's verbose and there might be lots of customized setActionHandler and ActionHandler with MediaSessionAction grows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.