Start learning with our library of video tutorials taught by experts. Get started
Viewers: in countries Watching now:
So now we have our video and audio embedded with HTML5. We have multiple versions of our source to support different HTML5 browsers. We're falling back to Flash for browsers that don't support HTML5 media. There's still one more step we could take to make our video even more accessible and that's to provide download links and a fallback image. The reason for this is to support users on devices that don't support HTML5 or Flash, but could still potentially play the video if they are able to download it directly. These devices are typically older mobile phones or PDAs.
The first step to do this is to add a simple paragraph after the video tag. So I am going to do that on our code. If you are following along in the exercise files, we're now in the 03_02 folder. Okay, I am going to drop down below our ending video tag, because this is going outside of our video tag, and I'm just going to provide simple paragraph and in the paragraph I am going to do a title. We'll put it in a strong tag that says Download Video.
And after that I'm going to provide the links to all our source versions. So link href and this would be our mp4 version. So I am just going to copy our source from our mp4 source and use that as the link URL. I'll call that MP4 and that anchor. I'm going to put a comma to separate the words. And then we'll do the same for our ogg source, and I'll call that OGG, and I am just going to copy that line and paste it after everything. Remove that last Comma.
We'll make this our webm source and tell that WEBM. I am just going to save that and jump over to Firefox and reload the page, and now we could see that we have download links below our video. So this is just an alternative way for users to access the video. Now they can download it by clicking on the links. All right, so the next thing we want to do is add a fallback image so that there isn't just a broken plug-in or blank space where the video should be. To do this, we have to modify our Flash embed code a little bit. So we'll go back and do that.
The Flash Media Playback Player uses an object and embed tag in its embed code, but this doesn't allow us to have a fallback image, because basically the embed tag acts as the fallback for the object tag. So we are going to need to change that to another Flash embed method that doesn't use the embed tag. So first let's breakup our embed code so we can see everything a little easier. So I am going to put line breaks ahead of the different parameter tags and the embed tag and I am going to drop the object down to the next line.
Okay, so now we have it broken up and the first thing I want to do is actually just go ahead and delete the embed tag. All right, now the way that we're going to make this work without the embed tag is actually add more information to our object tag and the first thing we're going to add is a type attribute and the type is application/x-shockwave-flash. And this is telling the object that it's a Flash Player and then we are going to add a data attribute.
The URL for the data attribute is going to be the same value for our Flash Player that's in the movie parameter, so I am going to go ahead and copy this. It's our SWF file that's used to load the video player. All right, so that's what we need to do to modify our code. What we are going to do next is add our fallback image and just like we added our fallback embed code after the source tags of our video tag, we are going to add our fallback image after the parameter tags in our object tag.
So it's the last thing in our object tag and it's just a simple image tag. And for the source of our fallback image, I often just use the poster image and so I am just going to copy our poster source here. But you can use any image you want here. You can use a generic image that just says something like your browser does not support video. Then beyond this we also want to add an alt and we'll say in alt No video supported and also a title here that says the same thing.
And we'll close that. Okay, so now we want to actually see this work. so what I am going to do is go back to the older version of Opera that I used in the Flash movie. That is a version of Opera before Opera supported HTML5 video, so that we can actually see how these fallbacks work. Now if I reload the Opera page you can see we're still supporting Flash so we can see the Flash Player still works. (Music plays) And then what I can do is actually go into the Opera preferences and you can do this in just about every browser.
I am going to turn off plug-ins. Now for Opera I would go to the Advanced Preferences tab and then the Content section, and then there's a checkbox that says Enable plug-ins. And you'll probably find something similar in your own browser. I am going to go ahead and disable plug-ins, I'll click OK, and then I am going to reload the page. We can see if I drag this it's now the image. It's now our poster image here instead of the Flash fallback and if we roll over it, you can see what we're putting on the title attribute. It says No video supported, so that's the value of adding the title attribute.
All right, so now we have it set up so that if the browser doesn't support HTML5, it will fall back to Flash, and if it doesn't support Flash, it will fall back to our fallback image. So again this step is to support that extra group of users on older devices and it is optional. If you're worried about your content being downloaded and spread across the Internet without your permission, you might want to skip this step. But in reality no video that's free to view on the Internet is 100% safe from being copied. So sometimes it's better to just support your users than to worry about that. But with that we finished our full HTML5 embed code.
I'll just back and look at it. I know it's probably not the most attractive code ever, but it's what we need to support our whole audience and hopefully in years to come it will get much easier than this to use HTML5 video and audio.
There are currently no FAQs about HTML5: Video and Audio in Depth.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
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.