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)

Displaying video through an Overlay (should know)


So far, we've concentrated on developing our basic video player, using jQuery. It's time now to change track, and take a look at another useful feature that you can use with HTML5 videos—overlays. This can help to give emphasis to displaying a video, as you can provide a mask to cover elements in the background, thereby removing some of the distraction.

Getting ready

For this task, you need to avail yourself of a copy of the shareware application VideoLightbox—at the time of writing, the latest version is 2.1, which is available from http://www.videolightbox.com. It is free for non-commercial use, so if you need to use it commercially, you will need to purchase a license that is $49 at the time of writing. You will also need a copy of a video in MP4 format—one of the ones you've converted, or used, from earlier will do fine.

Note

VideoLightBox only accepts a limited number of formats—at the time of writing, this includes SWF and MP4, but not WebM or OGG.

How to do it...

  1. Double-click on the videolightbox-setup.zip file, and run the videolightbox-setup.exe file, accepting all of the defaults.

  2. Once in VideoLightbox, click on Videos, then Add video from file—select your file, then click on Open. You will see your video listed, as shown in the following screenshot:

  3. Click on the Customize thumbnails tab, and select your options—for the purposes of this demo, I've chosen Polaroid as the Template format, followed by PNG - Portable Network Graphics for the Thumbnail format and the Play button, as shown in the following screenshot:

  4. On the next tab, Customize video, you can select from a number of options, including overlay template, resolution of video, and background color. For the purposes of this task, we will leave the defaults of Standard template, and a resolution of 640x480, unchanged.

  5. Click on the Publish tab, then on the Publish button—this will by default publish the video and code to a folder called VideoLightBox in your Documents folder. VideoLightbox will generate the code for you, and display the results in your default browser:

  6. We can then edit a copy of the source, and adapt it to our needs—here's a simplified example:

    <!DOCTYPE html>
    <html>
      <head>
        <title>VideoLightBox Test</title>
        <link type="text/css"rel="stylesheet" 
        href="index_videolb/videolightbox.css" />
        <link rel="stylesheet" type="text/css" 
        href="index_videolb/overlay-minimal.css"/>
        <script src="http://cdn.jquerytools.org/1.2.7/full/
        jquery.tools.min.js"></script>
        <script src="index_videolb/swfobject.js" 
        type="text/javascript"></script>
      </head>
      <body bgcolor="#f0f0f0">
      <div class="videogallery">
        <a class="voverlay" href="index_videolb/player.swf?url=video/bbb400p.mp4&volume=10  0" title="bbb400p">
      <img src="index_videolb/thumbnails/bbb400p.png"     alt="bbb400p" />
      <span></span>
      </a>
      </div>
      <script src="index_videolb/videolightbox.js"     type="text/javascript"></script>
      </body>
    </html>

How it works...

VideoLightbox uses a combination of jQuery Tools (http://www.jquerytools.org) and the SWFObject library (http://code.google.com/p/swfobject/)—the SWFObject acts as a container, into which a base player file is stored, and from within which the MP4 video is played. The jQuery Tools library is used to provide the overlay functionality. A call is made to the player "container" (in this instance player.swf), which stores an instance of our video, and is used to provide the stop/start controls for video playback.

Note

If you want to learn more about jQuery Tools, then you may like to take a look at another of my books, jQuery Tools UI Library, also available from Packt Publishing.

Summary

We've taken a look at a number of recipes, to show you how you can embed HTML5 video—using the new <video> tag—within your pages. This is only just the start of what you can achieve using the new tag—there is a whole world out there to explore. I hope you've enjoyed working through the recipes, just as much as I have enjoyed writing this book!