[whatwg] When to stop <video> elements from playing
Jonas Sicking
jonas at sicking.cc
Fri Oct 26 13:15:23 PDT 2007
A couple of comments:
The spec currently doesn't say to set the autoplaying flag to false when
an element is removed from the Document. I take it that will mean that
the element will start playing if it's currently waiting for data? This
seems undesirable to me for two reasons:
A) I think nodes not in the document should only start playing when more
explicitly asked to.
B) It creates a race condition where the element _will_not_ play when if
enough data had been downloaded at the point when the element was
removed, but _will_ play if it was still waiting for data.
Is there any reason we couldn't state the removing the element from the
Document calls pause() on the element?
I think that it is still currently possible that a currently playing
element can get garbage collected. Alternatively, that it is possible to
create elements that will never stop playing, even if the user navigates
away. Consider the following scenario:
1) Page A opens a new window containing Page B
2) Page A creates a reference to Page B
3) Page B creates an <audio> element that doesn't live in its Document
and sticks it in a global variable of its context.
4) Window containing Page B is closed. Page B does not go away since
Page A is holding a reference to it.
5) Page B calls .play() on the <audio>
6) Page A drops reference to Page B
7) Garbage Collection runs
8) User leaves Page A
9) Garbage Collection runs
The only step here that is slightly suspicious is step 5 since a
closed-but-alive page is running script. I believe this can happen in a
number of ways, the simplest being that Page A calls a function on Page
B. But I suspect there are also events that can fire in Page B even
after it has closed.
The question is, when does the <audio> element stop playing? If it stops
playing in step 7 we still have the situation that it can stop running
at a seemingly random point in time, i.e. when GC runs. Step 6 isn't
necessarily even needed since both Page A and Page B would get destroyed
in step 9 anyway.
If we say that the <audio> should not get garbage collected in step 7
since it is playing audio, at what point should it stop playing? There
is no connection between the <audio> and Page A so step 6 and 8 won't be
special in any way to the <audio>.
I believe the best solution here is to say that step 5 should throw an
exception. I.e. you can't start playing a media element whose
.ownerDocument is not a displayed document.
Other suggestions welcome.
/ Jonas
More information about the whatwg
mailing list