[whatwg] Scripted <video> query proposal

Tim Starling tstarling at wikimedia.org
Thu Aug 21 18:56:36 PDT 2008

interface HTMLMediaElement {
    boolean supportsType(in DOMString type);

The supportsType() method must return false if the user agent is sure it
cannot support the given type, and true if the user agent either can
support the given type, or cannot determine whether it can support the
given type.

The type parameter must be a MIME type. The codecs parameter may be
specified and might be necessary to specify exactly how the resource is
encoded [RFC2046] [RFC4281].

[end spec proposal]

Sample of simple detection JavaScript code:

div = document.getElementById('videocontainer');
video = document.getElementById( 'video1' );
if (!video.supportsType('application/ogg;codecs="theora")) {
    div.innerHTML = "Sorry, you can't play this content";
} else {

Complains only if the browser is sure it doesn't support the type,
otherwise it will try to play.

Sample of complex detection code:

supportsJava = navigator.javaEnabled && navigator.javaEnabled();
badVideo = false;
goodVideo = false;
if (HTMLVideoElement) {
    video = new HTMLVideoElement;
    if (!video) {
        // no <video> support
    } else if (video.supportsType('application/x-nonsense-type')) {
        badVideo = true;
    } else if (video.supportsType('application/ogg;codecs="theora"')) {
        goodVideo = true;
if (goodVideo) {
} else if (supportsJava) {
} else if (badVideo) {
} else {

Shows the <video> only if the browser is reasonably likely to support
it, or if there is no Java alternative.

-- Tim Starling

More information about the whatwg mailing list