Book Image

HTML5 Video How-To

By : Alex Libby
Book Image

HTML5 Video How-To

By: Alex Libby

Overview of this book

<p>Publishing videos online has been around for a number of years, although has really taken off with the advent of video sharing sites such as YouTube. The power of video is huge if done well; it can present a lot of information in a more visually engaging manner than using written text and pictures. Done badly though – it can present real problems to the company or individual hosting the video, that have the potential to cause some real harm!<br /><br />"HTML5 Video How-To" is a practical, hands-on guide that provides you with a number of clear step-by-step exercises, which will help you take advantage of the real power that is behind HTML5 video, and give you a good grounding in using it in your web pages.<br /><br />This book looks at the HTML5 video formats available, and breaks down the mystery and confusion that surrounds which format to use. It will take you through a number of clear, practical recipes that will help you to take advantage of the new HTML5 video standard, quickly and painlessly. <br /><br />You will also learn how to build your own video player using jQuery, or by using one of the pre-built libraries available. We will also take a look at adding functionality such as lightbox effects, or subtitles, as well as how to publish videos to popular hosting sites, such as YouTube or VideoBin. If you want to take advantage of using the new HTML5 video format, then this is the book for you.<br /><br />You will learn everything you need to know to convert videos into the right format, as well as how to display them in your browser or web pages, across multiple platforms.</p>
Table of Contents (8 chapters)

Providing fallback support (should know)


A key part of using the HTML5 <video> tag is that while the format is still evolving as a standard, it is still necessary to provide some form of fallback support for older browsers that cannot support the tag. In this task, we will look at providing that support.

Getting ready

In order to get the best out of this task, you will need to avail yourself of some means to be able to view your video pages within an older browser. There are several ways to achieve this, depending on which browser you choose:

  • Adobe BrowserLab : This will allow testing in various versions of IE, Chrome, Safari, and Firefox.

  • Firefox Portable (http://portableapps.com/apps/internet/firefox_portable): This will allow you to install a standalone version of Firefox, which won't affect any existing profiles on your PC. Legacy versions are available for older browsers.

  • For Internet Explorer: The best option here is to try using IETester; this has versions of IE built in all the way from 5.5 up to version 9. This is available for download from http://www.my-debugbar.com/wiki/IETester/HomePage.

  • Lunascape 6 (from http://www.lunascape.tv/): This is a triple-engined browser with support for Trident (IE), Gecko (Firefox), and Webkit (Chrome and Safari)-based browsers.

How to do it...

  1. To begin, open up your favourite text editor and copy in the following code snippet:

    <!doctype html>
    <html>
    <head>
    <title>HTML5 Video Test</title>
    </head>
    <body>
    <video width="720" height="400" controls="controls"   poster="trailer_480p.jpg">
      <source src="trailer_480p.webm" type="video/webm" />
      <source src="trailer_480p.mp4" type="video/mp4" />
      <source src="trailer_480p.ogv" type="video/ogg" />
    </video>
    </body>
    </html>
  2. Over the following three steps, we will create a fair amount of code beginning with the embedding of the <object> tag. Add in the following section of code immediately below the last <source> tag:

    <object type="application/x-shockwave-flash" 
      data=flashfox.swf" width="720" height="400" 
      style="position:relative;">
      <param name="movie" value="flashfox.swf" />
      <param name="allowFullScreen" value="true" />
      <param name="flashVars" value="autoplay=true&amp;controls=true&amp;loop=true&amp;src=trail    er_480p.mp4" />
  3. We also need to add in the equivalent using the <embed> tag immediately afterwards:

    <embed src="flashfox.swf" width="720" height="400" 
      style="position:relative;"  
      flashVars="autoplay=true&amp;controls=true&amp;
      loop=true&amp;poster=trailer_480p.jpg&amp;src=trailer_480p.mp4"
      allowFullScreen="true" wmode="transparent" 
      type="application/x-shockwave-flash" 
      pluginspage="http://www.adobe.com/go/
    getflashplayer_en" />
  4. The last stage is to add in a background image, and fall-back text; we then finish with the closing </object> tag:

    <img alt="trailer_480p" src="trailer_480p.jpg" 
      style="position:absolute;left:0;" width="720" 
      height="400" title="Video playback is not supported 
      by your browser" />
    </object>

How it works...

The aim of the code is to provide fallback support for displaying a Flash-equivalent movie; this is achieved by using a SWF-based container from which we run the MP4 file that would otherwise be run from within the <video> source tags. We also include a plain image and set a title attribute for it—this will be the "last-call" route that the browser will take if it is unable to play any of the videos listed within the code.

There's more...

While the previous code will work as a fall-back for the HTML5 video, there are some points to note:

  1. The <embed> tag is actually not a valid tag—it was designed to provide support for Netscape browsers in the early days, but more modern versions do support the <object> tag. The <object> tag was designed to provide support for IE browsers.

  2. The <object> tag is valid within HTML5—as a minimum, this should be used when providing fall-back support; I have provided an example for using the <embed> tag as well, although this is optional.