New Feature: Playlist Center! Pick a topic and let our playlists guide the way.

Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Embedding video

From: HTML Essential Training

Video: Embedding video

HTML5 provides a simple and powerful feature for embedding video in your web pages. Let's make a working copy of this video.html file here in the Chap10 folder of your exercise files. We will rename to video-working.html, and I am going to open that in the text editor, and we'll get to this JavaScript in a minute. You will see this file is actually very simple. It has header and the video and a form with some buttons. Let's go ahead and open this in the browsers.

Embedding video

HTML5 provides a simple and powerful feature for embedding video in your web pages. Let's make a working copy of this video.html file here in the Chap10 folder of your exercise files. We will rename to video-working.html, and I am going to open that in the text editor, and we'll get to this JavaScript in a minute. You will see this file is actually very simple. It has header and the video and a form with some buttons. Let's go ahead and open this in the browsers.

I am going to open this in both Firefox and Chrome. So there is, in Firefox, and you can see I can just press play. (video playing) And I can open this in Google Chrome, and we see there is the same video file. (video playing) And if we go back over here to our editor, you will see that it works exactly like the audio version, if you have looked at that movie. There is a video tag and inside of that container, there are three different source tags, and each of those is loading a different file with a different encoding.

There is MP4, there is webm, and there's ogg video. There's also this paragraph for browsers that don't support the feature. So what happens is the browser looks through this, and it looks at these media types, and it selects the first one that it supports. So if we go over here to Firefox and we come up here to the Tools menu and select Web Developer > Web Console, you see we have this message here that says, "video/mp4 is not supported." So it skips that file.

And if it skipped that file, it would have selected the webm file, because it didn't give us a message about failing with the webm file. And so if we come back over here to Tools > Page Info, select Media, you see that the webm file is the one that it selected, and here it is, down here. So this is a webm file, and if I come over to the Google Chrome browser, we can go through a similar exercise and find out which file it loaded.

Come down here to the Developer > Developer Tools, and in the Resources tab--it sometimes starts up in the console or one of these others. We select the Resources tab and under frames, video-working.html and you see under this XHR, if it's not opened up, that it selected the m4v file. And we see that that is the first one in the list. So this is a great feature for being able to provide a number of different encodings so that you can support all the different browsers in your audience.

So there's a couple of other attributes here to video tag. You notice that we have width and height, and we can actually set that to scale our media if we want to. We can make this 430 and we can make this 240, and now all of a sudden, it's going to load up a lot smaller in our window. And it scales it on the fly. (video playing) And the same thing works of course in Chrome. (video playing) This should really work in any browser.

We can also select the autoplay attribute. If I save that and reload this in my browser, you will see it starts playing right away. (video playing) And there's also a loop. So if I save that and bring that up in the browser, and again, this works in all the browsers as well. I bring this out towards the end, buffering a little bit.

You can see it's getting towards the end, and it loops right around. I can also get rid of the controls altogether. If I take out controls--I am just going to take all those out and just put in autoplay--and when I hit reload-- (video playing) So you see our controls are gone now from the video. So the only way to control is to provide our own controls, and of course, this is the same in Google Chrome. (video playing) So there are no controls available anymore.

The only way we can control this is by providing our own controls. So you can provide your own controls very, very simply. And again, this works exactly the same as it does with the audio tag, and this is exactly the same JavaScript; I've just changed the name of the variable to video. So we get the video object with getElementById, and the id is video1, and you see that the ID here is video1 in our video tag, and then we just provide these functions. And there's a few of them available. There is actually a few more than these available.

So we have play, we have pause, and we have rewind by setting the current time to 0, And these are attached. These buttons just simply like this onclick, and calling those functions. So these buttons just work fine. (video playing) I can rewind and start again. (video playing) So just like with the audio element, you can't actually style the controller with CSS, but you can provide your own controls. And that allows you to use all of your HTML and CSS skills to provide controls that fit perfectly in with the design of your site.

So the video tag is a very simple and powerful way to embed video elements in your web pages. By providing a selection of different encodings in the source tags, it's possible to support all of the modern browsers.

Show transcript

This video is part of

Image for HTML Essential Training
HTML Essential Training

82 video lessons · 94717 viewers

Bill Weinman
Author

 
Expand all | Collapse all
  1. 5m 24s
    1. Welcome
      56s
    2. Using the exercise files
      1m 37s
    3. What you need to know about this course
      2m 51s
  2. 22m 0s
    1. What is HTML?
      4m 12s
    2. Examining the structure of an HTML document
      7m 50s
    3. Understanding tags and containers
      6m 4s
    4. Exploring content models in HTML5
      2m 23s
    5. Looking at obsolete elements
      1m 31s
  3. 27m 19s
    1. Understanding whitespace and comments
      3m 53s
    2. Displaying text with paragraphs
      3m 37s
    3. Applying style
      8m 5s
    4. Using block and inline tags
      6m 34s
    5. Displaying characters with references
      5m 10s
  4. 16m 36s
    1. Exploring the front matter of HTML
      2m 9s
    2. Applying CSS to your document
      3m 59s
    3. Adding scripting elements
      4m 54s
    4. Using the meta tag
      3m 34s
    5. Optimizing your page for search engines
      2m 0s
  5. 24m 59s
    1. Controlling line breaks and spaces
      2m 46s
    2. Exploring phrase elements
      1m 44s
    3. Using font markup elements
      1m 5s
    4. Highlighting text with mark
      1m 29s
    5. Adding headings
      1m 38s
    6. Using quotations and quote marks
      3m 2s
    7. Exploring preformatted text
      1m 45s
    8. Formatting lists
      2m 28s
    9. Forcing text direction
      3m 49s
    10. Suggesting word-break opportunities
      2m 29s
    11. Annotating East Asian languages
      2m 44s
  6. 29m 15s
    1. Introducing CSS
      55s
    2. Understanding CSS placement
      6m 55s
    3. Exploring CSS syntax
      10m 34s
    4. Understanding CSS units of measure
      3m 3s
    5. Some CSS examples
      7m 48s
  7. 22m 5s
    1. Using images
      4m 13s
    2. Flowing text around an image
      4m 55s
    3. Breaking lines around an image
      3m 3s
    4. Aligning images
      5m 25s
    5. Mapping links in an image
      4m 29s
  8. 22m 28s
    1. Understanding URLs
      2m 41s
    2. Working with hyperlinks
      3m 28s
    3. Using relative URLs
      4m 20s
    4. Specifying a base URL
      2m 19s
    5. Linking within a page
      4m 12s
    6. Using image links
      5m 28s
  9. 17m 2s
    1. Exploring list types
      3m 52s
    2. List elements in depth
      7m 44s
    3. Using text menus with unordered lists
      5m 26s
  10. 15m 30s
    1. Introduction to HTML semantics
      4m 9s
    2. Exploring an example
      4m 56s
    3. Marking up figures and illustrations
      2m 33s
    4. Creating collapsible details
      3m 52s
  11. 11m 18s
    1. Embedding audio
      5m 19s
    2. Embedding video
      5m 59s
  12. 11m 53s
    1. Creating ad-hoc Document Object Model (DOM) data with the data-* attribute
      4m 53s
    2. Displaying relative values with meter
      2m 57s
    3. Creating dynamic progress indicators
      4m 3s
  13. 4m 49s
    1. Overview of HTML5 microdata
      1m 8s
    2. Exploring an example with microdata
      3m 41s
  14. 7m 3s
    1. Understanding outlines
      52s
    2. A demonstration of outlining
      6m 11s
  15. 13m 1s
    1. Table basics
      7m 29s
    2. Exploring the semantic parts of a table
      2m 32s
    3. Grouping columns
      3m 0s
  16. 9m 55s
    1. Frames overview
      54s
    2. Using traditional frames
      4m 26s
    3. Exploring inline frames using iframe
      2m 7s
    4. Simulating frames with CSS
      2m 28s
  17. 53m 7s
    1. Introducing forms
      10m 24s
    2. Using text elements
      10m 12s
    3. Using checkboxes and radio buttons
      2m 37s
    4. Creating selection lists and dropdown lists
      5m 14s
    5. Submit and button elements
      8m 48s
    6. Using an image as a submit button
      2m 15s
    7. Keeping context with the hidden element
      3m 0s
    8. Setting tab order
      2m 7s
    9. Preloading an autocomplete list using the datalist feature
      5m 26s
    10. Displaying results with output
      3m 4s
  18. 19m 47s
    1. Touring a complete site
      2m 14s
    2. Touring the HTML
      8m 44s
    3. Touring the CSS
      8m 49s
  19. 29s
    1. Goodbye
      29s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold

Are you sure you want to delete this note?

No

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
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.