Start learning with our library of video tutorials taught by experts. Get started

HTML5: Video and Audio in Depth

Setting up the JavaScript


From:

HTML5: Video and Audio in Depth

with Steve Heffernan
Expand all | Collapse all
  1. 1m 24s
    1. Welcome
      42s
    2. Using the exercise files
      42s
  2. 15m 18s
    1. Understanding HTML5 video and audio
      4m 46s
    2. The state of HTML5 video and audio
      4m 29s
    3. Understanding the format war
      3m 53s
    4. Configuring your server to deliver HTML5 media formats
      2m 10s
  3. 32m 36s
    1. Using the video and audio tags
      5m 34s
    2. Using multiple sources for browser compatibility
      5m 53s
    3. Preloading
      4m 16s
    4. Autoplaying
      2m 2s
    5. Looping
      5m 11s
    6. Setting a poster frame
      3m 43s
    7. Setting the video width and height
      3m 40s
    8. Displaying subtitles and captions
      2m 17s
  4. 12m 40s
    1. Falling back to Flash
      4m 4s
    2. Falling back to download links
      6m 21s
    3. Using an embed code builder
      2m 15s
  5. 22m 17s
    1. Understanding HTML5 video formats
      5m 10s
    2. Understanding HTML5 audio formats
      2m 57s
    3. Encoding MP4/H.264 video with HandBrake
      3m 13s
    4. Encoding Ogg, Theora, and WebM with Firefogg
      3m 18s
    5. Encoding audio formats with VLC
      5m 54s
    6. Automating video and audio encoding
      1m 45s
  6. 34m 59s
    1. Setting up the JavaScript
      4m 39s
    2. Creating Play and Pause buttons
      7m 52s
    3. Creating a Play Progress bar
      5m 49s
    4. Creating a Load Progress bar
      9m 29s
    5. Creating a Current Time and Duration display
      7m 10s
  7. 4m 37s
    1. Overview of known issues
      35s
    2. Autobuffer or preload?
      56s
    3. Load progress in Firefox 3.6
      41s
    4. Android 2.0 issues
      1m 5s
    5. iOS 3 issues
      1m 20s
  8. 2m 8s
    1. Flight of the Navigator
      50s
    2. ZEN Audio Player by simurai
      34s
    3. The Wilderness Downtown by Google and Arcade Fire
      44s
  9. 1m 40s
    1. Further exploration
      1m 40s

Video: Setting up the JavaScript

With HTML5 video, we also have a new powerful JavaScript API to the video that among other things allows us to build our own controls. This can be useful if you want the video controls to look the same across browsers. So that's what we are going to do now. What we are going to end up with is this here. It's very simple set of controls meant to give you an intro to the JavaScript API and then you can run with this from here, adding styles or images to make it look great. If you are interested in some of the other functions available in the video API, a good place to look is the video element page on the WHATWG site.

Watch this entire course now—plus get access to every course in the library. Each course includes high-quality videos taught by expert instructors.

Become a member
Please wait...
HTML5: Video and Audio in Depth
2h 7m Intermediate Jun 02, 2011

Viewers: in countries Watching now:

In this course, author Steve Heffernan contextualizes the state of HTML5 audio and video and shows how to embed media into a web page using HTML5. The course sheds light on configuring the new HTML5 audio and video tags, ensuring backwards compatibility by setting alternative playback methods, encoding the needed file formats, and building custom controls with JavaScript. Also included are tutorials on troubleshooting known issues and reviewing real-world examples of HTML5 audio and video.

Topics include:
  • Understanding the differences in media formats
  • Preloading, autoplaying, and looping in HTML5
  • Setting a video's width and height attributes
  • Displaying subtitles and captions
  • Generating embed code with an embed code builder
  • Encoding files using HandBrake, Firefogg, and VLC
  • Creating a load progress bar
  • Recognizing Android and iOS issues
Subjects:
Video Web Web Video Web Development
Software:
HTML
Author:
Steve Heffernan

Setting up the JavaScript

With HTML5 video, we also have a new powerful JavaScript API to the video that among other things allows us to build our own controls. This can be useful if you want the video controls to look the same across browsers. So that's what we are going to do now. What we are going to end up with is this here. It's very simple set of controls meant to give you an intro to the JavaScript API and then you can run with this from here, adding styles or images to make it look great. If you are interested in some of the other functions available in the video API, a good place to look is the video element page on the WHATWG site.

Okay, so I am going to go back to Firefox and the player we are building has some pretty basic functionality. It's got Play (Music playing) and Pause. The blue bar is going to show how much of the video has been loaded. The green bar is going to show us how far through the video we are and it also has the current time of the video and then the total duration of the video. All right, so that's what we are building. And let's go over to our code and see what we are starting with. If you are following along in your exercise files, we are now in the 5-01 folder of exercise files and what I have here is basically a scaled back version of our HTML5 page.

So it's the basic HTML5 page to make it easier to get to the code and work with the code. In the HTML5 I've included first jQuery, which is going to make it easier to work with the basic JavaScript functions. Then I have also included a JavaScript library and a CSS library that's going to apply directly to our player and we will look at that in a second. In the body of the page, we also have our video tag, but without any of the more complicated fallback content, which we don't need for this demonstration but you should still have in your final version.

Then I have also modified video tag a little. First I've added an ID of my_video so that we can reference to our video tag using JavaScript and then I have also removed the controls element. Remember before we had a controls attribute inside the video tag and I have removed that because we are going to be building our own controls. All right, let's go over and look at the JavaScript. All right! So in the JavaScript file I've start everything in a jQuery DOM-ready block which is what you see here and what that does is basically makes sure that our JavaScript doesn't run until all the elements that we want to work with are ready in the browser.

Then inside the block I have first a test to see if a HTML5 video is supported, which is this line here and what it's basically doing is creating a video element. So it's saying document.createElement and then on that element it's checking for the canPlayType method and if that method is supported it means that HTML5 video is supported. Otherwise it's not. Then in the front of this line I also have an exclamation point which means the opposite of the outcome of the line.

So it's basically asking if HTML5 video is not supported, then it goes down and we could see that if HTML5 isn't supported, I am using jQuery first to reference our video controls, which have the ID of video_controls, and then hide. So we're hiding the controls if HTML5 video isn't supported. Because in that case Flash would be showing and it would have its own set of controls. So we don't want to also see the controls that we are building now. Now then finally I have a variable that's going to store a reference to our video tag, and so I am using the document.getElementById function and then the my_video id that we put on the video tag.

So now in the rest of our JavaScript the video variable is going to reference our video tag. Okay, now let's go and look at the CSS file and in the CSS file I just have some basic styles around the controller. I have made it 480 pixels wide so it's the same width as our video and it has a height of 30 pixels and I put a gray background on it and the text color's going to be white, with Verdana as the font, font size of 12 pixels and then all the text is going to be upper case. And then the controls inside, the video_controls div, each individual control I have basically added a style to float them left.

So they are going to be in-line horizontally and they will have a height of 30 pixels and then a line height of 30 pixels to enforce that font size and line the font size right in the middle of the button. Okay, so that's our starting point and now we can start creating the controls.

There are currently no FAQs about HTML5: Video and Audio in Depth.

Share a link to this course
Please wait... Please wait...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.
Upgrade now


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Upgrade now

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed HTML5: Video and Audio in Depth.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Welcome to the redesigned course page.

We’ve moved some things around, and now you can



Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked