w3c / mediasession

Media Session API
https://w3c.github.io/mediasession/
Other
127 stars 30 forks source link

Support seekbackward and seekforward custom amount of time #205

Open beaufortfrancois opened 5 years ago

beaufortfrancois commented 5 years ago

More and more, "Seek Backward" and "Seek Forward" media controls show the amount of time in the icons directly (10s backward and 30s forward below). It would be great to support this as well in the Media Session API.

screenshot_20181121-132425

Here's what I'm proposing to kick off this discussion:

Proposal 1

Adding a simple way to specify the amount of time by appending it to the MediaSessionAction name.

// Show a 10s "Seek Backward" icon in the media session notification.
navigator.mediaSession.setActionHandler('seekbackward10', function() {
  // User clicked the 10s "Seek Backward" icon.
  video.currentTime = Math.max(video.currentTime - 10, 0);
});

// Show a 42s "Seek Forward" icon in the media session notification.
navigator.mediaSession.setActionHandler('seekforward42', function() {
  // User clicked the 42s "Seek Backward" icon.
  video.currentTime = Math.min(video.currentTime + 42, video.duration);
});

Proposal 2

Insert a new object parameter between MediaSessionAction an MediaSessionActionHandler in setActionHandler to specify a seekOffset key.

// Show a 10s "Seek Backward" icon in the media session notification.
navigator.mediaSession.setActionHandler('seekbackward', { seekOffset: 10 }, function() {
  // User clicked the 10s "Seek Backward" icon.
  video.currentTime = Math.max(video.currentTime - 10, 0);
});

// Show a 42s "Seek Forward" icon in the media session notification.
navigator.mediaSession.setActionHandler('seekforward', { seekOffset: 42 }, function() {
  // User clicked the 42s "Seek Backward" icon.
  video.currentTime = Math.min(video.currentTime + 42, video.duration);
});
chrisn commented 5 years ago

The current spec text mentions moving the playback time forward/backward "by a short period (eg. a few seconds)" so I'd support defining what the default seek interval is. And +1 to providing application level control, with preference for option 2.

scottlow commented 5 years ago

+1. Option 2 seems much cleaner to me.

mounirlamouri commented 5 years ago

I agree that option 2 is better. We may want to use this pattern for other actions. I'm thinking of skipad, to specify a count down timer.

ghost commented 5 years ago

We discussed this at the Web Media F2F and there was not interest from browsers to implement this for now. The main concern was around HCI issues with the icons e.g. having defined icons or what seek intervals a browser supports.

beaufortfrancois commented 5 years ago

Can you define HCI? Can't we generate icons on the fly?

jernoble commented 5 years ago

There are UAs who can’t generate icons on the fly in all the situations where this action would be used. For clients, there’s no good way to identify which UAs will honor this value or not.

Personally, I would like to support the broad use case of allowing clients to provide label hints for scenarios like “skip intro” and “skip ad”, but those are thornier issues.

And IIRC, HCI stands for “human-computer interaction”.

youennf commented 1 year ago

Marking as enhancement. It seems more thoughts are needed to come up with a proposal.