-
Notifications
You must be signed in to change notification settings - Fork 29
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
Introduce way to expose supported MediaSession actions? #148
Comments
The DOM specification recommends against this pattern. |
@annevk This proposal is copacetic with the DOM recommendation. No page-visible behavior is observable due to setting this eventListener. The spec is (correctly) silent about how the UA exposes these actions to the OS. @mounirlamouri It sounds like your display problems would be solved by "enqueuing a task" in spec parlance. |
@jernoble if the only way this can be implemented is via adding event listeners having side effects, I wouldn't call it copacetic. |
That's incorrect. In the very basic use case, hitting a hardware pause button would fire |
So why is OP talking about UI modifications based on the presence of event listeners? |
Both Android and iOS have software controls for changing playback state. The UA (or the platform on which the UA runs) has to decide what controls to display, which is why @mounirlamouri brought it up. |
For those it would make more sense if the app could indicate what UI actions have an effect somehow. Listeners don't really tell you that one way or another. |
If we provided a way for the page to indicate it supports "next track" commands (e.g.) which the page author set but then didn't add a "next track" event listener, I'm not going to display a "next track" UI because I'm pretty sure it won't do anything. |
@xxyzzzq @beaufortfrancois and I have been talking about these. None of us is super happy with the current situations. One of the reason is the side effect of adding an event handler. Another is that some events should definitely have a default action but some probably shouldn't. For example, Chrome will likely force to pause all players after We came up with the following proposal: enum MediaSessionAction {
"play",
"pause",
"previoustrack",
"nexttrack",
"seekforward",
"seekbackward",
};
[Constructor(sequence<MediaSessionAction> actions)]
interface MediaSessionActions : EventTarget {
attribute EventHandler onplay;
attribute EventHandler onpause;
// onplaypause was removed in favour of using the MediaSessionPlayback.state
attribute EventHandler onprevioustrack;
attribute EventHandler onnexttrack;
attribute EventHandler onseekbackward;
attribute EventHandler onseekforward;
};
partial interface MediaSession {
attribute MediaSessionActions? actions;
}; That way, a website can specify which actions it supports by doing Then, the In summary, the main changes from this proposal are:
There are likely better ways to do this so comments welcome :) |
I see the proposal of @mounirlamouri moved the control into a new object, which is the opposite of #45 . I think there's a reason why we flattened the media controls into MediaSession. We need to keep that in mind. |
What would happen if I'm not sure why we need to create navigator.mediaSession.actions.addEventListener('play', function(event) {
// Do stuff...
}); |
Otherwise, what you propose is what we have today with various events, right? The idea with creating the object is that it's easier to set a contract that the page will then handle the actions it says it will. It also solves the issue of the side effect of event listening. Another approach is to have a method or attribute that will be used to mark the handled actions. In general, I'm not strongly against the side effects of listening to the events but I would prefer if there was no default behaviour apart from |
After discussing with @xxyzzzq and @beaufortfrancois, we came up with an alternative. The idea would be to not use It would look like this: navigator.mediaSession.setActionHandler('nexttrack', () => {
Playlist.next();
});
navigator.mediaSession.setActionHandler('pause', () => {
Player.pause();
}); Obviously, it is very similar to the event listener pattern but we can then specify our own rules which is that handling an event means that the user agent will step doing any default behaviour and will use this as a signal that the website supports the action. This is only an idea to get the discussion moving so please feel free to leave feedback :) |
I'm not a huge fan of the method name |
I like the idea of making these "action handlers" rather than "event listeners". I might suggest calling this
Which would allow clients to write code like:
|
That sounds reasonable to me. My understanding of the named property is that we would need to define a getter, setter and deleter in addition of the get/set/remove methods. Furthermore, we would need to reject if the action isn't supported. Those look like details to me though. @annevk @slightlyoff any objection? |
What you proposed seems reasonable, though I thought some Chrome engineers had reservations about new callback-based APIs. You don't want to use named getters/setters/deleters. They cause conflicts between actual members of the object and things you want to look up. Just use short method names. (Once https://www.w3.org/Bugs/Public/show_bug.cgi?id=26986 is fixed for IDL this should be more clear.) |
To summarize, I've added |
The current specification allow a website to set events in order to control MediaSession actions. Having an event listener for an action is used by the UA to decide whether to show a button in its UI (per spec). In addition of introducing side effects when listening to an event, this is creating strange behaviour where a page will modify the MediaSession UI when adding the event listeners (on Android, the notification will flicker). This would also happen when a page will change its event handler (ie.
session.onplay = foo; session.onplay = foo;
will add/remove twice).Should we have a more straightforward way to expose that a page can handle/support some actions without creating an event listener? or are we happy with the current situation and we expect implementers to find workarounds for the side effects?
/CC @annevk @slightlyoff for general feedback
/CC @jernoble for implementer feedback
The text was updated successfully, but these errors were encountered: