[whatwg] [html5] r4685 - [e] (0) Add an example of forcing fallback from <source>.

On Wed, 10 Feb 2010 03:27:45 +0100, <whatwg at whatwg.org> wrote:

> Author: ianh
> Date: 2010-02-09 18:27:42 -0800 (Tue, 09 Feb 2010)
> New Revision: 4685
>
> Modified:
>    complete.html
>    index
>    source
> Log:
> [e] (0) Add an example of forcing fallback from <source>.
>
> Modified: complete.html
> ===================================================================
> --- complete.html	2010-02-10 02:14:17 UTC (rev 4684)
> +++ complete.html	2010-02-10 02:27:42 UTC (rev 4685)
> @@ -21749,8 +21749,32 @@
>   </div>
> +  <div class=example>
> +   <p>If the author isn't sure if the user agents will all be able to
> +   render the media resources provided, the author can listen to the
> +   <code title=event-error>error</code> event on the last
> +   <code><a href=#the-source-element>source</a></code> element and  
> trigger fallback behaviour:</p>
> +   <pre>&lt;video controls autoplay&gt;
> + &lt;source src='video.mp4' type='video/mp4; codecs="avc1.42E01E,  
> mp4a.40.2"'&gt;
> + &lt;source src='video.ogv' type='video/ogg; codecs="theora, vorbis"'
> +         onerror="fallback(parentNode)"&gt;
> + ...
> +&lt;/video&gt;
> +&lt;script&gt;
> + function fallback(video) {
> +   // replace &lt;video&gt; with its contents
> +   while (video.hasChildNodes())
> +     video.parentNode.insertBefore(video.firstChild, video);
> +   video.parentNode.removeChild(video);
> + }
> +&lt;/script&gt;</pre>

The script should probably be before the video, because it's possible that  
a UA will fire the error event before having parsed the script defining  
the function.

Also, the script results in invalid HTML since it puts <source>s outside  
<video>.

-- 
Simon Pieters
Opera Software

Received on Wednesday, 10 February 2010 04:31:09 UTC