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)

Adding controls to your player (must know)


The first task of this section was quite a lengthy one, which was necessary so that we could add in the base framework required to display the video using our custom player. It's now time to add in the code for the custom controls—this will provide the framework for the play and pause buttons, as well as a slider for seeking, and a button for controlling the volume.

Getting ready

For this task, as we are only adding code, all we need is our text editor.

How to do it...

  1. Open up the videoplayer.html file saved from the previous task, and add in the following code below the </video> closing tag. We start with the play, pause, and time slider placeholder elements:

    <div class="custom_controls">
      <a class="play" title="Play"></a>
      <a class="pause" title="Pause"></a>
    <div class="time_slider"></div>
  2. We then continue with the time placeholder elements:

    <div id="time">
      <span class="timer">00:00:00</span> /
      <span class="duration">00:00:00</span>
    </div>
  3. We finish with the volume control element:

    <div class="volume">
      <div class="volume_slider"></div>
        <a class="mute" title="Mute"></a>
        <a class="unmute" title="Unmute"></a>
      </div>
    </div>

How it works...

If we are using the <video> tags in HTML, then the browser will provide its own set of controls. However, as seen in the previous section, these controls will differ depending on which browser is used—they will not all be the same. The purpose of this section is to begin to create our own controls, so that we can provide a consistent appearance, no matter which browser you use to view the videos. There will be scope for you to add additional ones once you get more familiar with building players. A good example is the ability to show an icon that changes depending on what position the volume control has been set.