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 VideoJS—an example player (become an expert)


Throughout this section, we've had a look at the code required to produce a basic HTML5 video player on a web page as well as the options available for configuring the player. For this task and the next, we are going to look at a couple of examples of pre-built players that are available for download from the Internet - namely VideoJS and Kaltura. Both are open-source applications, and are available at no cost.

Getting ready

For this, we don't actually need to download any files—VideoJS is one of those rare players that is available on a Content Delivery Network (CDN); it is enough to link to the files for the purpose of this task.

How to do it...

  1. Crank up your text editor and add the following code snippet:

    <!doctype html>
    <html>
    <head>
    <title>HTML5 Video Test</title>
    </head>
    <body>
    </body>
    </html>
  2. Let's begin adding in the JavaScript library and CSS calls in your <head> tags:

    <link href="http://vjs.zencdn.net/c/video-js.css" rel="stylesheet">
    <script src="http://vjs.zencdn.net/c/video.js"></script>
  3. The bulk of the code required to run the player is very similar to the code we've used throughout this section—the differences have been highlighted:

    <video id="my_video_1" class="video-js vjs-default-skin"   controls preload="auto" width="720" height="400"     poster="trailer_480p.jpg" data-setup="{}">
      <source src="trailer_480p.mp4" type='video/mp4'>
      <source src="trailer_480p.webm" type='video/webm'>
    </video>

If all is well, you will have a video playing similar to the following screenshot:

How it works...

The player uses very similar code to that we've used throughout this section—the styling however has been customized using additional CSS and JavaScript (similar to what we will see in the next section). This means that a consistent style can be used throughout most (if not all) platforms, which is infinitely preferable to the mix of styles you will otherwise see if you are not using the same styles on all platforms! The added benefit here is that because the JS and CSS files are hosted on a CDN, you don't need to worry about updating the code as this is done for you automatically. The code can also be downloaded separately if you prefer to host it locally.

Tip

If you want to try out a few designs, visit http://www.kaltura.org/apis/html5lib/kplayer-examples/Player_Themable.html—this has a standalone player linked to jQuery UI's ThemeRoller, where you can choose different styles. Note: if you change to a different theme in the gallery, give it about five seconds to refresh the screen before continuing