Video
HTML5 defines a new element called <video>
for embedding video in your web
pages. Embedding video used to be impossible without third-party plug-ins
such as Apple QuickTime or Adobe Flash.
The <video>
element is
designed to be usable without any detection scripts. You can specify
multiple video files, and browsers that support HTML5
video will choose one based on what video formats they support.[2]
Browsers that don’t support HTML5 video will ignore
the <video>
element completely,
but you can use this to your advantage and tell them to play video through
a third-party plug-in instead. Kroc Camen has designed a solution called
Video for
Everybody! that uses HTML5 video where available,
but falls back to QuickTime or Flash in older browsers. This solution uses
no JavaScript whatsoever, and it works in virtually every browser,
including mobile browsers.
If you want to do more with video than plop it on your page and play
it, you’ll need to use JavaScript. Checking for video support uses
detection technique #2 (see Detection Techniques). If
your browser supports HTML5 video, the
DOM object it creates to represent a <video>
element will have a canPlayType()
method. If your browser doesn’t
support HTML5 video, the DOM object it
creates for a <video>
element
will have only the set of properties common to all elements. You can check
for video support using this function:
function supports_video() { return !!document.createElement('video').canPlayType; }
Instead of writing this function ...
Get HTML5: Up and Running now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.