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)

Embedding videos—the old school way (must know)


We will begin this section with a timely reminder of how to embed videos into web pages using the classic <embed> and <object> tags.

Getting ready

For this task, you will need to avail yourself of two videos—one in SWF format and the other in WMV format. If you don't have any available at hand, there might be examples available on the Internet. One such example is the trailer for "Big Buck Bunny", available from the Peach Open Movie Project at http://www.bigbuckbunny.org/index.php/trailer-page/. You might have to convert it to the proper formats required for this demo—a good program to use for this is XMedia Recode, which is available at http://www.xmedia-recode.de (German language).

How to do it...

  1. Open up your favourite text editor and add the following code snippet—save this as videotemplate.html; we will be reusing this in later tasks:

    <!doctype html>
    <html>
    <head>
    <title>Embedding a video using <embed> and <object> tags</title>
    </head>
    <body>
    </body>
    </html>
  2. Add the following code snippet in between the <body></body> tags, replacing example.swf and videofilename.wmv with the filenames of your chosen videos:

    <!-- code for embedding windows media player -->
    <object id="mediaplayer" width="192" height="190" classid="clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95"standby="Loading Windows Media Player components..." type="application/x-oleobject"><param name="filename" value="videofilename.wmv"><param name="autostart" value="false"><param name="showcontrols" value="true"><param name="showstatusbar" value="false"><param name="showdisplay" value="false"><embed type="application/x-mplayer2" src="videofilename.wmv" name="mediaplayer"width="192" height="190" showcontrols="1" showstatusbar="0" showdisplay="0" autostart="0"></embed></object>
    <!-- code for embedding adobe quicktime -->
    <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/
    cabs/flash/swflash.cab#version=6,0,40,0" width="468" height="60" id="mymoviename"> <param name="movie" value="example.swf" /><param name="quality" value="high" /> 
    <param name="bgcolor" value="#ffffff" /> 
    <embed src="example.swf" quality="high" bgcolor="#ffffff"
      width="468" height="60" name="mymoviename" align=""     type="application/x-shockwave-flash" 
    pluginspage="http://www.macromedia.com/go/getflashplayer"> 
    </embed> 
    </object>

This is an example of what you will see when using the Windows Media player code—I'm using a copy of the "One Big Rabbit" video, available from the Peach Open Movie Project, as shown in the following screenshot:

How it works...

The code embeds an instance of each of the Windows Media Player and Adobe QuickTime plugins within the webpage; it uses the codebase attribute to reference the relevant plugin. If a hash value is included in the URL provided for this attribute, then the browser will compare this version with the one currently installed and either use it or download a more recent version.

There's more...

The preceding code snippet highlights a couple of major drawbacks: the embed code doesn't work in all browsers despite using the <embed> and <object> tags within the code block; it also requires the use of external plugins in order to operate correctly.

In the next task, we will be looking at how the preceding code snippet can be simplified using HTML5's <video> tag.