[mediacapture-main] Clarification about ended event and attribute on HTML media elements.

guidou has just created a new issue for https://github.com/w3c/mediacapture-main:

== Clarification about ended event and attribute on HTML media elements. ==
The spec says:

> If the element is an HTMLVideoElement, then when the MediaStream state moves from the active to the inactive state, the User Agent MUST raise an ended event on the HTMLVideoElement and set its ended attribute to true. 

My first observation is that setting the ended attribute of a media element seems to be in conflict with the definition of that attribute in the HTML spec. The ended attribute in HTML is not defined as something that can be arbitrarily set, but in terms of duration and current playback position as follows:
> A media element is said to have ended playback when:
> The element's readyState attribute is HAVE_METADATA or greater, and
> Either:
> * The current playback position is the end of the media resource, and
> * The direction of playback is forwards, and
> * The media element does not have a loop attribute specified.
> Or:
> * The current playback position is the earliest possible position, and
> * The direction of playback is backwards.
> * The ended attribute must return true if, the last time the event loop reached step 1, the media element had ended playback and the direction of playback was forwards, and false otherwise.

About infinite streams, the HTML spec says:
> If an "infinite" stream ends for some reason, then the duration would change from positive Infinity to the time of the last frame or sample in the stream, and the durationchange event would be fired. Similarly, if the user agent initially estimated the media resource’s duration instead of determining it precisely, and later revises the estimate based on new information, then the duration would change and the durationchange event would be fired.

Should the madiacapture-main  spec be more explicit either about overriding the ended attribute or redefining what should happen in terms of current playback position and duration?

I would also like clarification about the following:

> Note that once ended equals true the HTMLVideoElement will not play media even if new MediaStreamTracks are added to the MediaStream (causing it to return to the active state) unless autoplay is true or the web application restarts the element, e.g., by calling play().

Is the part about not playing media when the stream becomes active a description of what will happen, given how HTML elements work, or is this mandating that the element must be paused when it becomes ended? If the latter, I think this must be mentioned more explicitly.

I noticed that Firefox and Edge pause the element. In addition, Firefox fires the pause event (which I think is required by the HTML spec if the element becomes paused). If play() is invoked on the element before the stream becomes active, the element plays the stream automatically when it becomes active. Chrome does not pause the element and the stream is played automatically when it becomes active again.
My conclusion is that if the intent of the spec is that playback should not resume, it must explicitly state that the element must be paused. Otherwise, the text saying that the element will not automatically play a stream that becomes active should be removed.

I would also like clarification about what should happen to the duration and currentTime fields in the HTML element.
Based on the HTML spec, it looks like duration should change from infinity to the time of the last frame. The mediacapture-main spec says nothing about duration, and, in practice, Firefox, Edge and Chrome always keep it as Inifinity, even if the stream has ended.

With regards to currentTime, the spec says  the initial value is 0 and the values increments linearly in real time whenever the stream is playing. Can it be reset to zero if the stream ends (and possibly restarts)? 
In practice, Edge and Chrome reset to zero and start increasing currentTime again when the stream becomes active. The version of Firefox I tried (61.0b13) does not reset to zero, but it seems to have a bug since it does not continue increasing currentTime after the stream becomes active again.

Please view or discuss this issue at https://github.com/w3c/mediacapture-main/issues/536 using your GitHub account

Received on Wednesday, 5 September 2018 12:25:10 UTC