w3c/mediasession

Issue for the definition of `duration` in `MediaPositionState`

Closed this issue · 4 comments

The definition of durtaion [1] in MediaPositionState is that it should always be positive.

It conflicts with the step of setPositionState()[2], where the spec mentions that ....its value is null, throw a TypeError. But when converting null to number, null is actually equal to +0 [3] that is also considered as a positive number, which is acceptable by the definition.

From my perspective, setting duration to 0 is meaningless, so I would suggest to explicitly mention that duration can't be zero in the duration's definition and replace all null description in setPositionState() with 0. Because using null is really ambiguous.

[1] https://w3c.github.io/mediasession/#dom-mediapositionstate-duration
[2] https://w3c.github.io/mediasession/#dom-mediasession-setpositionstate
[3] http://www.ecma-international.org/ecma-262/5.1/#sec-9.3

Okay, I got a correction, so apparently +0 is not considered as positive.

If so, the issue would become simply replace null with 0 to make sentence clearer.

And one more question is that, do we allow duration to be set to 0 ?

Quote from [1],
So if 0 duration is supposed to be allowed, that informative text should be fixed to say "not negative" or so and the "is null" check in the algorithm steps should be removed. If 0 duration is supposed to be forbidden, the informative text is fine and the algorithm steps should replace "value is null" with "value is 0".

[1] https://phabricator.services.mozilla.com/D66500#2025051

chrisn commented

Should we align duration more with HTMLMediaElement.duration, i.e., unrestricted double, which would allow for unbounded duration, represented with +Infinity? This is so webapps can simply use mediaElement.duration without needing to do additional checks before calling setPositionState. It would mean allowing zero, although I agree it doesn't seem useful, and also we'd need steps to handle NaN.

IMO, since the primary use case of MediaSession is to interact (bidirectionally) with HTMLMediaElement, duration should allow the same (if not more) values that HTMLMediaElement.duration does.

+Infinity is commonly used to signal "Live streams", and should be supported as well.