[whatwg] Scripted <video> query proposal; Query supported formats for media elements

Ian Hickson ian at hixie.ch
Mon Oct 13 16:10:53 PDT 2008

This e-mail is a reply to two threads asking for a way to see if a type is 
supported. As with the earlier thread on the same topic, it is something 
that I think would be good if we could provide it, but my understanding is 
that it isn't something that is realistically going to be reliably 
implemented and thus it is something that I have not added to the spec 
yet. I welcome feedback from implementors who can show that this is 
usefully implementable on multiple platforms. If we could in fact support 
this, that would be great.

On Fri, 22 Aug 2008, Tim Starling wrote:
> interface HTMLMediaElement {
>     ...
>     boolean supportsType(in DOMString type);
>     ...
> }
> [...]

Without a way for browsers to reliably implement this, it doesn't seem 
like this would be any better than just providing the video and then 
testing to see if it actually plays.

>     video = new HTMLVideoElement;

Note that that won't work; you need createElement('video').

On Tue, 2 Sep 2008, Maik Merten wrote:
> I'm trying to find out how to determine if a given media format is 
> supported by a media-element implementation.

Try to play all the videos you have available, and catch errors:

  <video id=a>
   <source src="video.mp4" type="video/mp4; codecs="avc1.42E01E, mp4a.40.2"">
   <source src="video.3gp" type="video/3gpp; codecs="mp4v.20.8, samr"">
   <source src="video.ogv" type="video/ogg; codecs="theora, vorbis"">
   <source src="video.mkv" type="video/x-matroska; codecs="theora, vorbis"">
   if (document.getElementById('a').currentSrc == "") {
     // failed to find a video that would play
     // do whatever fallback you want to do here

This will reliably work, because load() blocks until a decision about 
which video to play is made.

We may have to change this (e.g. to allow UAs to asynchronously fetch and 
try each video), in which case I'll make onerror fire reliably in the case 
of no video being found. (In that case I'll also make type="" optional on 
<source>, since it'd be a hint only.)

Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'

More information about the whatwg mailing list