[whatwg] HTML Audio Element removal from DOM

Simon Pieters simonp at opera.com
Wed Jan 18 01:01:21 PST 2012


On Tue, 17 Jan 2012 23:44:58 +0100, Charles Pritchard <chuck at jumis.com>  
wrote:

>> When a media element is removed from a Document, the user agent must  
>> run the following steps:
>> 	1. Asynchronously await a stable state, allowing the task that removed  
>> the media element from the
>> 		Document to continue. The synchronous section consists of all the  
>> remaining steps of this algorithm.
>> 		(Steps in the synchronous section are marked with.)
>> 	2. If the media element is in a Document, abort these steps.
>> 	3. If the media element's networkState attribute has the value  
>> NETWORK_EMPTY, abort these steps.
>> 	4. Pause the media element.
>
> This seems to reflect the current webkit behavior. The element is paused  
> when it's removed from the Document.
> I'll focus on the bug report I'm putting together.
> function example() {
> var a = audioElement.parentNode.removeChild(audioElement);
> a.play(); // there is an audible pause.
> };

This, per spec, should cause the element to be paused. See step 1 above.  
a.play() will run before the algorithm reaches step 4. Currently you would  
need to wait for the "paused" event and play() from there. We could change  
the spec so that play() sets a flag on the element that the algorithm  
above checks before pausing the element, or some such, to make the above  
do the intended.

-- 
Simon Pieters
Opera Software



More information about the whatwg mailing list