HTML YouTube Videos
HTML YouTube Videos (YouTube视频)
Sometimes you may want to convert your videos to other formats to make them play in all browsers. However, it can be difficult and time-consuming to convert videos to other formats. An easier way is to let YouTube play the videos on your web page. (有时,您可能需要将视频转换为其他格式,以便在所有浏览器中播放。但是,将视频转换为其他格式可能既困难又耗时。更简单的方法是让YouTube播放您网页上的视频。)
When saving or playing a video, YouTube will display an id which you can use to refer to a video in the HTML code. (保存或播放视频时, YouTube将显示一个ID ,您可以使用该ID在HTML代码中引用视频。)
Playing a YouTube Video in HTML
Playing a YouTube Video in HTML (以HTML格式播放YouTube视频)
If you want to play your video on a web page, follow these steps:
Upload the video to YouTube Take a note of the video id Specify an <iframe> element in your web page Make the src attribute point to the video URL Use the height and width attributes for defining the dimension of the player Add other parameters to the URL
Example of playing a YouTube video in HTML with the <iframe> element:
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
</head>
<body>
<iframe width="560" height="315" src="https://www.youtube.com/embed/i8n1gSw_o_8"></iframe>
</body>
</html>
YouTube Autoplay
YouTube Autoplay (YouTube自动播放)
You can also make your video start playing automatically when visiting that page. For this, add a parameter to your YouTube URL. (您还可以在访问该页面时自动开始播放视频。为此,请在YouTube网址中添加参数。)
If the value is 0 (default), the video will not start playing automatically when the player loads. If the value is 1, the video will start playing automatically when the player loads. (如果值为0 (默认值) ,则当播放器加载时,视频不会自动开始播放。如果值为1 ,则当播放器加载时,视频将自动开始播放。)
Example of YouTube autoplay:
<!DOCTYPE html> <html> <head> <title>Title of the document</title> </head> <body> <iframe width=“560” height=“315” src=“https://www.youtube.com/embed/i8n1gSw_o_8?autoplay=1”> </iframe> </body> </html>
Besides the original URL, there can be a comma separated list of videos to play (YouTube playlist). (除了原始网址外,还可以用逗号分隔要播放的视频列表( YouTube播放列表)。)
YouTube Controls
YouTube Controls (显示 Youtube 控制)
If the value is 0, the player controls will not display. If the value is 1(default), the player controls will display. (如果值为0 ,则播放器控件将不会显示。如果值为1 (默认值) ,则将显示播放器控件。)
Example of YouTube controls:
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
</head>
<body>
<iframe width="560" height="315" src="https://www.youtube.com/embed/i8n1gSw_o_8?controls=0">
</iframe>
</body>
</html>
YouTube Loop
YouTube Loop
If the value is 0 (default), the video will play only once. If the value is 1, the video will loop endlessly. (如果值为0 (默认值) ,视频将只播放一次。如果值为1 ,视频将无休止地循环。)
Example of Youtube loop:
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
</head>
<body>
<iframe width="560" height="315" src="https://www.youtube.com/embed/i8n1gSw_o_8?playlist=tgbNymZ7vqY&loop=1">
</iframe>
</body>
</html>
YouTube - Using the HTML <embed> or <object> tags
YouTube - Using the HTML <embed> or <object> tags
YouTube <embed> and <object> elements are deprecated. Instead, you should use <iframe>.
Example of adding YouTube videos with the <embed> element:
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
</head>
<body>
<embed width="560" height="315" src="https://www.youtube.com/embed/i8n1gSw_o_8">
</body>
</html>
Example of adding YouTube videos with the <object> element:
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
</head>
<body>
<object width="560" height="315" data="https://www.youtube.com/embed/i8n1gSw_o_8">
</object>
</body>
</html>