W3C home > Mailing lists > Public > whatwg@whatwg.org > August 2008

[whatwg] Scripted <video> query proposal

From: Tim Starling <tstarling@wikimedia.org>
Date: Fri, 22 Aug 2008 11:56:36 +1000
Message-ID: <48AE1CD4.3020006@wikimedia.org>
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
Received on Thursday, 21 August 2008 18:56:36 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:59:04 UTC