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

012 Embedding videos for all browsers and devices

From: View Source

Video: 012 Embedding videos for all browsers and devices

Hello! This is Ray Villalobos and welcome to View Source. In this episode, I'm going to show you how to create a page that serves video to regular browsers and iOS devices without having to recompress the files in multiple formats. How is that possible? Let's View Source. HTML5 tags are revolutionary. Theoretically, it's possible to embed video or audio in a web site by adding a simple tag that's as easy to use as the image tag. The problem with using this tag is that older browsers do not support the media tags, but there's another problem.

012 Embedding videos for all browsers and devices

Hello! This is Ray Villalobos and welcome to View Source. In this episode, I'm going to show you how to create a page that serves video to regular browsers and iOS devices without having to recompress the files in multiple formats. How is that possible? Let's View Source. HTML5 tags are revolutionary. Theoretically, it's possible to embed video or audio in a web site by adding a simple tag that's as easy to use as the image tag. The problem with using this tag is that older browsers do not support the media tags, but there's another problem.

Newer browsers do not support the same format. Almost every major browser supports a slightly different file format. So if you want to show one video to every browser, you might have to encode files in WebM, Ogg, and MP4. Here I have what should be the way all browsers work; you have a simple video tag that links with the source attribute to a file on your site. You specify a width and a height and controls, so that shows the controls that people can use to play, pause, and scrub through the movie. So I am going to copy that, and paste that into this video player, and I am going to save this file.

I'm working with files that are stored in a server. So now that I've placed the files on the server, I'm going to pull up Safari and load this file. So as you can see, the file loads up fine and it plays in Safari. If I try to pull up the same file in Firefox, although I see the default player for Firefox, I can't see the video. It's not that Firefox doesn't understand the HTML5 video tag; it's that it doesn't understand the format that this video is in. In order to support as many browsers as possible, I would like to use Flash for desktop browsers and HTML5 for iOS devices, since if I choose a Flash only solution, iOS devices will not be able to understand Flash video.

Now one problem that you might run into when testing this solution out on your local machine is that Flash is picky about access to external files, and this is the reason why I am working off of a live server. So if you are working on local files, make sure you upload into a server before you preview your solution. So what I like to do is use a video player called flowplayer that is a free Flash-based player that works great on all desktop devices. So I am going to hit the Download link right here, and I'm going to scroll down so you can see the different licenses that I can get.

You can get commercial licenses for this product, but I like the free license. So I am going to use that. So I'll click on Download and it will download the file. Once it decompresses, you'll get a folder with a series of documents. You are going to need these two SWF files right here as well as some of the information in the example. From the example folder, you are going to need this flowplayer JavaScript document. I've already copied those on to my server, you can see the flowplayer is right here and the two SWF files are right underneath. So now I need to load my JavaScript libraries because I am going to be using JavaScript in order to make this work.

So I need to go right here and copy the scripts for this file. So I need to call my own JavaScript file where I am going to write a script to detect whether or not the device is an iOS device, as well as the flowplayer script. So I am going to copy that and open up my index.html document. Hit the Edit button here, and I am going to add that to my head section right here, add the two calls to the script. I already have the scripts loaded up on my server. You can see this script is already right there. So I am going to save that, and I also need to modify my video tag so that it's not the HTML5 tag, but it's a call to function that I've defined in myscript document.

So I am going to copy that, and come up here, replace my video tag with the new version that's my JavaScript call. So this particular function is going to take the name of the video file that I want to play, as well as dimensions, and then a player name that will be something I can target with CSS. So after I do that, I have a couple of versions of this function. So one way to attack this problem would be to build a function that works only using Flash as a player, and that is this first version of my function that essentially uses the flowplayer to play the files.

I have the two calls that I would normally use just to use flowplayer and I have a call to a method right here that gives flowplayer a couple of variables. The other option is to use this modified version of the form that actually checks the user agent, that means it checks to see which browser is trying to access this document, and then determines if the browser that is using this document comes from an iPhone, an iPod, or an iPad and if it does, then it uses the same video tag that we used before. Otherwise, it's going to use the normal flowplayer and that's what we have done in our version of the myscript file.

We'll make that little bigger so you can see it better. So you could see that this takes the information from the script, if the device is an iOS device, then it just writes out the normal video tag. If it's not an iOS device, then it uses flowplayer to display the video. So now I'm going to save the script, and I'm going to pull this up in Firefox, reload this page, and you can see that the flowplayer takes over and I am going to go Safari, refresh this page, once again flowplayer is taken over on desktop devices.

So now, it not only plays on desktop browsers, but will also play on any iOS device. So I wouldn't count out Flash just yet, it's an especially good solution for delivering online video, especially for older browsers. Tune in next time and don't forget that to solve just about any online project, sometimes the best solution is to View Source.

Show transcript

This video is part of

Image for View Source
View Source

20 video lessons · 15876 viewers

Ray Villalobos
Author

 

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


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.

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 View Source.

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

Your file was successfully uploaded.

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.