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)

Setting up Kaltura video—an example player (become an expert)


In this task, we're going to take a look at the second of two example video players, which is the Kaltura open-source video player. The software is available at http://www.kaltura.org/project/HTML5_Video_Player, and can be used from a CDN link or a version downloaded locally.

Getting ready

Kaltura's Video Player is available from a CDN link—we'll be using this as part of the task, so we don't need anything extra for this task.

How to do it...

  1. Open up your text editor of choice and insert the following code snippet:

    <!DOCTYPE HTML>
    <html>
    <head>
      <title> Sample Fallback Player </title>     
    </head>
    <body>
    <div></div>
    </body>
    </html>
  2. We start by adding in the call to jQuery and the Kaltura library:

    <head>
      <title> Sample Fallback Player </title>     
    <script type="text/javascript"     src="http://html5.kaltura.org/js"></script> </head>
  3. We need a container within which we hold the video, so go ahead and alter the <div> tag as follows:

    <body>
    <div id="videoContainer" style="width:500px;height:300px;"></div>
  4. The final stage is to add in the code that calls the videos:

    <div id="videoContainer" style="width:500px;height:300px;">
    <video id="vid1" width="480" height="267" durationHint="33" 
    poster="trailer_480p.jpg">
    <source type="video/webm" src="trailer_480p.webm" />
    <sourcesrc="trailer_480p.mp4"/>
    <source src="trailer_480p.ogv" />
    </video></div>

If all is well, you will see something similar to the following screenshot:

How it works...

The video player works by reusing the standard format code for <video>, but deploying CSS and some JavaScript to redesign the controls using progressive enhancement principles. Using jQuery UI, this gives the player a consistent theme across all browsers; the theme used can be altered at will using the Theme Roller applet as shown in the following screenshot:

Unlike some players that rely on JavaScript to specify the video to play, Kaltura's video will still play if JavaScript is disabled as it will use the standard browser controls—this is known as progressive enhancement .

Note

If you would like to learn more about jQuery UI Theme development, it is worth having a look at jQuery UI Theme Development—A Beginner's Guide, by Adam Boduch.

So far, we've looked at how you can embed video using the <video> tags, as well as adapting your web pages to cater for video playback through a number of different browsers. In this section, we will focus on how you can write your own video player by looking at the following:

  • Building and packaging your own video player using jQuery

  • Adding controls to your video player

  • Styling your video player and providing a color theme

  • Inserting subtitles

  • Providing fall-back support using a jQuery polyfill

  • Displaying video through an Overlay

Note

For the purposes of each task, we're using the trailer videos for the open-source movie, "The Big Bunny", available from the Peach Open Movie Project at http://www.bigbuckbunny.org/index.php/trailer-page/. The videos are © copyright 2008, Blender Foundation/www.bigbuckbunny.org, unless otherwise indicated.