Skip to main content

HTML Lesson#04 HTML YouTube Videos By Naeem Raza

The easiest way to play videos in HTML, is to use YouTube.


Struggling with Video Formats?

Earlier in this tutorial, you have seen that you might have to convert your videos to different formats to make them play in all browsers.
Converting videos to different formats can be difficult and time-consuming.
An easier solution is to let YouTube play the videos in your web page.

YouTube Video Id

YouTube will display an id (like tgbNymZ7vqY), when you save (or play) a video.
You can use this id, and refer to your video in the HTML code.


Playing a YouTube Video in HTML

To play your video on a web page, do the following:
  • Upload the video to YouTube
  • Take a note of the video id
  • Define an <iframe> element in your web page
  • Let the src attribute point to the video URL
  • Use the width and height attributes to specify the dimension of the player
  • Add any other parameters to the URL (see below)



Example - Using iFrame (recommended)

<iframe width="420" height="315"
src="https://www.youtube.com/embed?v=jiPkV46sR0k"
>

</iframe>


YouTube Autoplay

You can have your video start playing automatically when a user visits that page by adding a simple parameter to your YouTube URL.
Note: Take careful consideration when deciding to autoplay your videos. Automatically starting a video can annoy your visitor and end up causing more harm than good.
Value 0 (default): The video will not play automatically when the player loads.
Value 1: The video will play automatically when the player loads.

<iframe width="560" height="315" src="https://www.youtube.com/embed/jiPkV46sR0k" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>

YouTube Playlist

A comma separated list of videos to play (in addition to the original URL).

YouTube Loop

Value 0 (default): The video will play only once.
Value 1: The video will loop (forever).

YouTube - Loop

<iframe width="420" height="315"
src="https://www.youtube.com/embed/jiPkV46sR0k?playlist=tgbNymZ7vqY&loop=1"
>

</iframe>

YouTube Controls

Value 0: Player controls does not display.
Value 1 (default): Player controls display.

YouTube - Controls

<iframe width="420" height="315"
src="https://www.youtube.com/embed/jiPkV46sR0k?controls=0"
>

</iframe>

YouTube - Using <object> or <embed>

Note: YouTube <object> and <embed> were deprecated from January 2015. You should migrate your videos to use <iframe> instead.

Example - Using <object> (deprecated)

<object width="420" height="315"
data="https://www.youtube.com/embed/jiPkV46sR0k"
>

</object>

Example - Using <embed> (deprecated)

<embed width="420" height="315"
src="https://www.youtube.com/embed/jiPkV46sR0k"
>
Like Your Own Blogg :https://academyofprogramming.blogspot.com

Comments

Popular posts from this blog

Using JavaFX in a NetBeans Application – Part 2

Part1 discussed how to use JavaFX to visualize data and other content in a NetBeans Platform application window. We showed you how to create JavaFX content from a TopComponent using FXML and a FXML controller class. In this post we describe the communication strategies you can use when integrating JavaFX content within a TopComponent (NetBeans Platform window). Communication Strategies The overriding goal in integrating JavaFX content in a TopComponent is to keep the JavaFX scene graph and its controller class encapsulated. Figure 1 shows the TopComponent, which is managed by the NetBeans Platform window system and communicates directly with the NetBeans Platform framework. Figure 1. Embedding JavaFX in a TopComponent The TopComponent invokes the FXMLLoader, which reads the FXML, builds the JavaFX scene graph, and instantiates the controller class. Any further manipulation of the scene graph from the TopComponent should go through public methods you provide in the contr...

Cpp Tutorials

1-Introduction   1.1 Intro To C++   1.2 Advantages and Disadvantages 2-An Example of C++ Program   2.1 Structure of Program 3-Variables and Operators   3.1 Variables   3.2 Variables Scope   3.3 Constants-Literals   3.4 Variables Storage Classes   3.5 Operators 4-Compund Types   4.1 Array   4.2 String   4.3 Pointer   4.4 Structure   4.5 Reference   4.6 Enumration and Type Def 5-Input and Output   5.1 Cout (Output Stream)   5.2 Cin  (Input Stream)   5.3 Cerr (Error Stream)   5.4 Clog (Log Stream) 6-Flow of Control 6.1 Conditional Branching if 6.2 Conditional Selection Switch 6.3 Loop-While and For 6.4 Break and Continue 6.5 Random Number 7-Functions   7.1 Function Basics   7.2 Declaration ,Call and Arguments   7.3 Inline Function   7.4 Recursion 8-Object Oriented Approach   8.1 Classes Basics   8.2 Cons...

Using JavaFX in a NetBeans Application – Part 1

We like the idea of visualizing application data with JavaFX. JavaFX makes it easy to add effects such as drop shadows, background gradients, and reflection to window content. You can also apply animations to rotate, scale, fade in or out, and move JavaFX elements. And, JavaFX is a viable solution if your visualization requirements include charts or 3D. In this post, we discuss some of the issues you will encounter when integrating JavaFX content in a NetBeans Platform application. Here are two examples of NetBeans Platform applications with integrated JavaFX content. Figure 1 shows a NetBeans Platform window displaying a JavaFX pie chart, with one of its slices animating after a mouse click. Figure 1. Pie Chart Animation Figure 2 shows a NetBeans Platform application with JavaFX 3D content. The left window shows the 3D Box primitive, which rotates when the window’s slider is adjusted. The right window shows 2D shapes with different depths in 3D space that also rotate when...