[whatwg] When to stop <video> elements from playing
mjs at apple.com
Fri Oct 19 11:40:38 PDT 2007
On Oct 18, 2007, at 3:28 PM, Robert O'Callahan wrote:
> Suppose a script creates a <video> element, adds it to the document,
> starts it playing, then removes the element from the document and
> drops all references to it. When should the element stop playing?
> -- when the element leaves the document?
> -- when all JS references to the element have been dropped (and
> garbage collection runs)?
> -- when the user leaves the page?
> -- when the end of the stream is reached? (which could be "never")
I think it would be ok to do a one-time stop of a playing <video> and
<audio> element at the time it is removed from the document, but still
allow at least <audio> (and maybe <video> too for consistency, though
it seems gratuitous) to play play if is outside the document already
when it starts. In any case, like <img>, I think loading should be
able to proceed when outside the document or set to display: none.
Stopping at remove time ensures that sounds and videos end at a
deterministic time when parts of the document are replaced, say with
innerHTML. Without this, if you replace a piece of the document that
may contain <video> or <audio> elements you will have to search for
them first and make sure to stop them. However, if the element can
still start to play when outside the document, that addresses the use
case for programmatic audio for things like game sound effects.
More information about the whatwg