In the last article, we learned about HTML videos and how we can add them easily to our web pages. We have seen that it is very difficult and struggle that some browsers do not support specific video format. So to play them in different browsers you any have to add different types of video format and for that, you have to convert videos manually from one format to another. Is there a better option?
Definitely, yes!
An easier solution is to let YouTube play the videos for you. When you upload(or watch) a video on youtube, you will see that YouTube has the unique id for each video. We can use this id to play video on our web pages and yes, it will play on all the browsers and operating systems. Let's see how we can achieve this...
Let's see what code looks like:
<iframe width="420" height="315" src="https://www.youtube.com/embed/oZikw5k_2FM" frameborder="0" gesture="media" allow="encrypted-media" allowfullscreen>
</iframe>
We can write the same code in simplified format as follows:
<iframe width="420" height="315"
src="https://www.youtube.com/embed/oZikw5k_2FM">
</iframe>
We use the <iframe> tag to describe the video here with following attributes:
Definitely, yes!
An easier solution is to let YouTube play the videos for you. When you upload(or watch) a video on youtube, you will see that YouTube has the unique id for each video. We can use this id to play video on our web pages and yes, it will play on all the browsers and operating systems. Let's see how we can achieve this...
YouTube Videos
The simplest way to use a YouTube video on the HTML page is to head to any youtube video, right click and select "Copy Embed Code". This will directly copy the required HTML, to use.Let's see what code looks like:
<iframe width="420" height="315" src="https://www.youtube.com/embed/oZikw5k_2FM" frameborder="0" gesture="media" allow="encrypted-media" allowfullscreen>
</iframe>
We can write the same code in simplified format as follows:
<iframe width="420" height="315"
src="https://www.youtube.com/embed/oZikw5k_2FM">
</iframe>
We use the <iframe> tag to describe the video here with following attributes:
- width and height : To describe the size of the video
- src : To describe the source of video(last part of URL is nothing but unique id)
- frameborder : 0 for no border around video, 1 for border
- allowfullscreen : Allows the user to watch the video in full screen
- controls : 1 for showing controls(default), 0 for not showing controls
- loop: 1 for looing videos, 0 for not(default)
- Others are less important and browser-specific attributes, so neglect them
Comments
Post a Comment