[whatwg] Scripted <video> query proposal

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 {
    video.play();
}

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) {
    embedVideo();
} else if (supportsJava) {
    embedCortado();
} else if (badVideo) {
    embedVideo();
} else {
    showErrorMessage();
}

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

-- Tim Starling

Received on Thursday, 21 August 2008 18:56:36 UTC