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

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

HTML5: Video and Audio in Depth
Illustration by

Using multiple sources for browser compatibility


From:

HTML5: Video and Audio in Depth

with Steve Heffernan

Video: Using multiple sources for browser compatibility

In the video tag movie, I mentioned that the previous example of using the ogg formats wouldn't work in Safari or IE 9. Well if we'd use the MP4 formats instead, the example wouldn't have worked in Firefox, Chrome or Opera. So in this movie, I'm going to show you how to provide multiple sources so both sets of browsers can play the video. If you're following along with the exercise files, we're now in the 2-02 folder. We're back to our single source video tag. The first thing we want to do is add a source tag and the source tag allows us to provide multiple sources for the video.
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

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

Using multiple sources for browser compatibility

In the video tag movie, I mentioned that the previous example of using the ogg formats wouldn't work in Safari or IE 9. Well if we'd use the MP4 formats instead, the example wouldn't have worked in Firefox, Chrome or Opera. So in this movie, I'm going to show you how to provide multiple sources so both sets of browsers can play the video. If you're following along with the exercise files, we're now in the 2-02 folder. We're back to our single source video tag. The first thing we want to do is add a source tag and the source tag allows us to provide multiple sources for the video.

The source tag also has a source or src attribute. And for our first source we're going to use the same file that we used for the video tag before. So I'm just going to copy and paste that from the previous one and at the same I'm going to remove the source attribute from the video tag. We don't want that there anymore because now we're using the source tags to provide our sources. All right the next attribute we need in the source tag is the type attribute.

And for this file the type is "video/ogg". Now what the type attribute does is, basically tell the browser what type of video it is. So it can look through the list of sources and skip over the ones that it knows it can't play, instead of having to look at each file to see if it can play it. Then finally we want to add a closing slash for this tag. In HTML5 the source tag is a self- closing tag, so we don't need a closing tag and we really don't need this closing slash for HTML5 standards but I've run into issues where browsers don't close this tag correctly and so I always add the slash at the end.

so I suggest you do it too. Now we have our first source and what we can do is basically just copy that to create our second source. I'm going to go ahead and paste that above our previous one and this source is going to be podcast.mp4 and use our mp4 version and the type is video/mp4. So the way the source list works is the browser will scan through the list of sources until it finds one that it can play.

It'll start from the top to the bottom. As soon as it finds one that it can play, it'll play that source and if it gets to the end of the source list, it will fallback to the fallback content. So that's why we want the sources first and then the fallback content after that. So that's very important order there. Now, we want the mp4 source above the ogg source. We want that first because of a bug in the iPad. The iPad will actually hit the first source and if it can't play that, it will just stop. So other browsers will continue looking through the sources but the iPad will only check the first source and so for that reason we have to have the mp4 first.

All right, so now we have one more source to add. So I'm going to go and copy one of our previous sources. I'm going to add this one between the two and this is our webm format. So it's podcast.webm and the video type is "video/webm". Now the reason I'm putting it above the ogg source is because the webm is a higher-quality format and is supported by the same browsers as ogg but not supported by as many browsers or as many browser versions as ogg.

So, we want it first so if the browser can play webm, it'll play the webm version and otherwise it'll play the ogg version. So the order goes mp4, then webm, then ogg. That's the best way to order your source files based on everything else involved. So let's go ahead and save that and go to our browser. We're now in the 2-02 folder and reload the page. Now we can see that in webm, we're playing the webm version. So I have a watermark in the video that shows us (music playing) we're playing the webm version.

So great, that part's working. I'm going to go ahead and copy this URL and open up Safari, in which we'll be playing the mp4 version. And if we scroll down we can see, yup. (Music playing) We can see by the watermark that says MP4 and so great. Now it's playing in both Safari and in Firefox. so it supports both the browsers that support the open formats and the browsers that support the closed formats. So let's go and do audio as well.

Going back to our code, let's just copy one of our source tags from the video tag and use that. We're going to use the source that we used before in the audio tag for our first source. At the same time, remove the source attribute from the audio tag so we don't want that there anymore. And then the type of this source is "audio/ogg".

Then our second source, again this one is going to go above the previous one because of the iPad bug, and this is our m4a source and the type is "audio/mp4". So those are the two sources that we need for audio and we can save that and go to our web browser, reload the page. We don't have a nice watermark to tell us that it's playing but we can see-- (Audio playing) --hat it does work in Firefox and we can go into Safari, reload the page.

(Audio playing) And it works there as well. So awesome. Our video and audio now work across HTML5 browsers. And now we can move on to looking at some of the other attributes of the video and audio tag.

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

 
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

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.

join now 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
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.

Are you sure you want to delete this note?

No

Notes cannot be added for locked videos.

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.