[whatwg] When to stop <video> elements from playing

Robert O'Callahan robert at ocallahan.org
Thu Oct 18 22:12:03 PDT 2007


On Oct 19, 2007 11:55 AM, Geoffrey Garen <ggaren at apple.com> 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?
>
> Probably. Since you can't see the video any more, it would be really
> weird to hear audio from it, or waste computer resources on a mute and
> invisible video. Moreover, there's a lot of precedent for DOM elements
> not loading when they're not in the document. This is true of iframe,
> script, img, etc.


It's not true of <img>. Javascript image preloading tricks rely on it.

And as Maciej mentioned, it would be useful to be able to play audio outside
the document, and to be consistent, <video>'s behaviour should match.


> > -- when all JS references to the element have been dropped (and
> > garbage collection runs)?
>
> No. The time at which garbage collection will reclaim an object is
> unpredictable, so relying on garbage collection for behavior is a bad
> idea.


Agreed.


> > -- when the user leaves the page?
>
> Certainly. But you might want to stop the video sooner.


Agreed.


> > -- when the end of the stream is reached? (which could be "never")
>
> Certainly. (How can you play past the end of the stream?) But you
> might want to stop the video sooner.
>

Agreed.

A related question is whether display:none audio and video elements should
produce sound.

My current opinion is that <audio> and <video> elements should behave like
<img> and load/play whether or not they're in a document, but they should
only emit sound if they're in a document with a presentation and are not in
a display:none subtree. Then to play a sound you'd have to insert the
element into your document somewhere with size 0x0 (which should be the
default for <audio>).

But it's a rather tangled issue.

Rob
-- 
"Two men owed money to a certain moneylender. One owed him five hundred
denarii, and the other fifty. Neither of them had the money to pay him back,
so he canceled the debts of both. Now which of them will love him more?"
Simon replied, "I suppose the one who had the bigger debt canceled." "You
have judged correctly," Jesus said. [Luke 7:41-43]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.whatwg.org/pipermail/whatwg-whatwg.org/attachments/20071019/af0677e4/attachment-0001.htm>


More information about the whatwg mailing list