[whatwg] Media element delaying load event

There's an additional problem with the current media load algorithm 
spec, it's possible to cause two resource-selection asynchronous calls 
to run in parallel with the following javascript:

var v = document.createElement("video");
v.src = "foo.ogg";
v.load();
document.body.appendChild(v);

The load() method will asynchronously invoke the media element's 
resource selection algorithm, and if the resource selection algorithm 
doesn't execute fast enough in the background to change the 
networkState, when we add the video to the document and the networkState 
is still NETWORK_EMPTY, the add-to-a-document code will asynchronously 
invoke the resource selection algorithm again.

I think we should either:

1. Change the networkState in the load() method. This will prevent 
another asychronous invokation of the resource selection algorithm when 
we add the media element to a document, or
2. never asynchronously invoke the resource selection algorithm if 
there's another instance running, or
3. add a guard at the start of the resource selection algorithm to abort 
the async call if there's already another instance running.

Because we have waiting in the load algorithm now, there's no need to 
have multiple instances of the resource selection algorithm active. So 
option 2 is probably the easiest.

I still think we need to delay the load event in the load() method, 
rather than in the resource selection algorithm, as I said in my 
previous post.


Thanks,
Chris Pearce.


On 4/03/2009 10:17 a.m., Chris Pearce wrote:
> The media element spec says:
>> If a media element
>> <http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html#media-element>
>> whose |networkState
>> <http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html#dom-media-networkstate>|
>> has the value |NETWORK_EMPTY
>> <http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html#dom-media-network_empty>|
>> is inserted into a document
>> <http://www.whatwg.org/specs/web-apps/current-work/multipage/infrastructure.html#insert-an-element-into-a-document>,
>> the user agent must asynchronously invoke the media element
>> <http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html#media-element>'s
>> resource selection algorithm
>> <http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html#concept-media-load-algorithm>.
>>
> The resource selection algorithm then goes on to set the
> delaying-the-load-event flag to true. Depending on how the asynchronous
> invocation is implemented, the document could actually complete loading
> during the time after the insertion of a media element, but before the
> resource-selection algorithm sets the delaying-the-load-event flag is
> set to true. This means the load event could fire during that time, even
> though we intended to delay the load event.
>
> Maybe we should set the delaying-the-load-event flag to true before we
> asynchronously call the resource-selection algorithm, and then then
> resource-selection algorithm can set the delaying-the-load-event flag to
> false if that decides it needs to wait for a src or source element child?
>
> Thanks,
> Chris Pearce.
>
>

Received on Thursday, 5 March 2009 14:37:37 UTC