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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset