Overview
This document explains how to embed a YouTube player in your application and also defines the parameters that are available in the YouTube embedded player.
By appending parameters to the IFrame URL, you can customize the playback experience in your application. For example, you can automatically play videos using the autoplay parameter or cause a video to play repeatedly using the loop parameter. You can also use the enablejsapi parameter to enable the player to be controlled via the IFrame Player API.
This page currently defines all parameters supported in any YouTube embedded player. Each parameter definition identifies the players that support the corresponding parameter.
Embedded players must have a viewport that is at least 200px by 200px. If the player displays controls, it must be large enough to fully display the controls without shrinking the viewport below the minimum size. We recommend 16:9 players be at least 480 pixels wide and 270 pixels tall.
Embed a YouTube player
You can use any of the following methods to embed a YouTube player in your application and specify player parameters. Note that the instructions below demonstrate how to embed a player that loads a single video. The following section explains how to configure your player to load other types of content, such as playlists and search results.
Embed a player using an <iframe> tag
Define an <iframe> tag in your application in which the src URL specifies the content that the player will load as well as any other player parameters you want to set. The <iframe> tag's height and width parameters specify the dimensions of the player.
If you create the <iframe> element yourself (rather than using the IFrame Player API to create it), you can append player parameters directly to the end of the URL. The URL has the following format:
https://www.youtube.com/embed/VIDEO_ID
The <iframe> tag below would load a 640x360px player that would play the YouTube video M7lc1UVf-VE. Since the URL sets the autoplay parameter to 1, the video would play automatically once the player has loaded.
<iframe id="ytplayer" type="text/html" width="640" height="360"
src="https://www.youtube.com/embed/M7lc1UVf-VE?autoplay=1&origin=http://example.com"
frameborder="0"></iframe>
Embed a player using the IFrame Player API
Follow the IFrame Player API instructions to insert a video player in your web page or application after the Player API's JavaScript code has loaded. The second parameter in the constructor for the video player is an object that specifies player options. Within that object, the playerVars property identifies player parameters.
The HTML and JavaScript code below shows a simple example that inserts a YouTube player into the page element that has an id value of ytplayer. The onYouTubePlayerAPIReady() function specified here is called automatically when the IFrame Player API code has loaded. This code does not define any player parameters and also does not define other event handlers.
<div id="ytplayer"></div>
<script>
// Load the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// Replace the 'ytplayer' element with an <iframe> and
// YouTube player after the API code downloads.
var player;
function onYouTubePlayerAPIReady() {
player = new YT.Player('ytplayer', {
height: '360',
width: '640',
videoId: 'M7lc1UVf-VE'
});
}
</script>
Select content to play
You can configure your embedded player to load a video, a playlist, a user's uploaded videos, or search results for a particular query.
The following list explains these options:
Loading a video
For an IFrame embed, the YouTube video ID for the video that you want to load is specified in the IFrame's src URL.
https://www.youtube.com/embed/VIDEO_ID
If you are using the YouTube Data API (v3), you can programmatically construct these URLs by retrieving video IDs from search results, playlist item resources, video resources, or other resources. After obtaining a video ID, replace the VIDEO_ID text in the URLs above with that value to create the player URL.
Loading a playlist
Set the listType player parameter to playlist. In addition, set the list player parameter to the YouTube playlist ID that you want to load.
https://www.youtube.com/embed?listType=playlist&list=PLAYLIST_ID
Note that you need to prepend the playlist ID with the letters PL as shown in the following example:
https://www.youtube.com/embed?listType=playlist&list=PLC77007E23FF423C6
If you are using the YouTube Data API (v3), you can programmatically construct these URLs by retrieving playlist IDs from search results, channel resources, or activity resources. After obtaining a playlist ID, replace the PLAYLIST_ID text in the URL above with that value.
Loading a user's uploaded videos
Set the listType player parameter to user_uploads. In addition, set the list player parameter to the YouTube username whose uploaded videos you want to load.
https://www.youtube.com/embed?listType=user_uploads&list=USERNAME
Loading search results for a specified query
Set the listType player parameter to search. In addition, set the list player parameter to the query term for which you want the player to load search results.
Parameters
autoplay
This parameter specifies whether the initial video will automatically start to play when the player loads. Supported values are 0 or 1. The default value is 0.
cc_load_policy
Setting the parameter's value to 1 causes closed captions to be shown by default, even if the user has turned captions off. The default behavior is based on user preference.
color
This parameter specifies the color that will be used in the player's video progress bar to highlight the amount of the video that the viewer has already seen. Valid parameter values are red and white, and, by default, the player uses the color red in the video progress bar. See the YouTube API blog for more information about color options.
Note: Setting the color parameter to white will disable the modestbranding option.
controls
This parameter indicates whether the video player controls are displayed. For IFrame embeds that load a Flash player, it also defines when the controls display in the player as well as when the player will load. Supported values are:
controls=0 – Player controls do not display in the player. For IFrame embeds, the Flash player loads immediately.
controls=1 (default) – Player controls display in the player. For IFrame embeds, the controls display immediately and the Flash player also loads immediately.
controls=2 – Player controls display in the player. For IFrame embeds, the controls display and the Flash player loads after the user initiates the video playback.
Note: The parameter values 1 and 2 are intended to provide an identical user experience, but controls=2 provides a performance improvement over controls=1 for IFrame embeds. Currently, the two values still produce some visual differences in the player, such as the video title's font size. However, when the difference between the two values becomes completely transparent to the user, the default parameter value may change from 1 to 2.
disablekb
Setting the parameter's value to 1 causes the player to not respond to keyboard controls. The default value is 0, which means that keyboard controls are enabled. Currently supported keyboard controls are:
Spacebar or [k]: Play / Pause
Arrow Left: Jump back 5 seconds in the current video
Arrow Right: Jump ahead 5 seconds in the current video
Arrow Up: Volume up
Arrow Down: Volume Down
[f]: Toggle full-screen display
[j]: Jump back 10 seconds in the current video
[l]: Jump ahead 10 seconds in the current video
[m]: Mute or unmute the video
[0-9]: Jump to a point in the video. 0 jumps to the beginning of the video, 1 jumps to the point 10% into the video, 2 jumps to the point 20% into the video, and so forth.
enablejsapi
Setting the parameter's value to 1 enables the player to be controlled via IFrame or JavaScript Player API calls. The default value is 0, which means that the player cannot be controlled using those APIs.
For more information on the IFrame API and how to use it, see the IFrame API documentation. (The JavaScript Player API has already been deprecated.)
end
This parameter specifies the time, measured in seconds from the start of the video, when the player should stop playing the video. The parameter value is a positive integer.
Note that the time is measured from the beginning of the video and not from either the value of the start player parameter or the startSeconds parameter, which is used in YouTube Player API functions for loading or queueing a video.
fs
Setting this parameter to 0 prevents the fullscreen button from displaying in the player. The default value is 1, which causes the fullscreen button to display.
hl
Sets the player's interface language. The parameter value is an ISO 639-1 two-letter language code or a fully specified locale. For example, fr and fr-ca are both valid values. Other language input codes, such as IETF language tags (BCP 47) might also be handled properly.
The interface language is used for tooltips in the player and also affects the default caption track. Note that YouTube might select a different caption track language for a particular user based on the user's individual language preferences and the availability of caption tracks.
iv_load_policy
Setting the parameter's value to 1 causes video annotations to be shown by default, whereas setting to 3 causes video annotations to not be shown by default. The default value is 1.
list
The list parameter, in conjunction with the listType parameter, identifies the content that will load in the player.
If the listType parameter value is search, then the list parameter value specifies the search query.
If the listType parameter value is user_uploads, then the list parameter value identifies the YouTube channel whose uploaded videos will be loaded.
If the listType parameter value is playlist, then the list parameter value specifies a YouTube playlist ID. In the parameter value, you need to prepend the playlist ID with the letters PL as shown in the example below.
https://www.youtube.com/embed?
listType=playlist
&list=PLC77007E23FF423C6
Note: If you specify values for the list and listType parameters, the IFrame embed URL does not need to specify a video ID.
listType
The listType parameter, in conjunction with the list parameter, identifies the content that will load in the player. Valid parameter values are playlist, search, and user_uploads.
If you specify values for the list and listType parameters, the IFrame embed URL does not need to specify a video ID.
loop
In the case of a single video player, a setting of 1 causes the player to play the initial video again and again. In the case of a playlist player (or custom player), the player plays the entire playlist and then starts again at the first video.
Supported values are 0 and 1, and the default value is 0.
Note: This parameter has limited support in the AS3 player and in IFrame embeds, which could load either the AS3 or HTML5 player. Currently, the loop parameter only works in the AS3 player when used in conjunction with the playlist parameter. To loop a single video, set the loop parameter value to 1 and set the playlist parameter value to the same video ID already specified in the Player API URL:
https://www.youtube.com/v/VIDEO_ID?
version=3
&loop=1
&playlist=VIDEO_ID
modestbranding
This parameter lets you use a YouTube player that does not show a YouTube logo. Set the parameter value to 1 to prevent the YouTube logo from displaying in the control bar. Note that a small YouTube text label will still display in the upper-right corner of a paused video when the user's mouse pointer hovers over the player.
origin
This parameter provides an extra security measure for the IFrame API and is only supported for IFrame embeds. If you are using the IFrame API, which means you are setting the enablejsapi parameter value to 1, you should always specify your domain as the origin parameter value.
playlist
This parameter specifies a comma-separated list of video IDs to play. If you specify a value, the first video that plays will be the VIDEO_ID specified in the URL path, and the videos specified in the playlist parameter will play thereafter.
playsinline
This parameter controls whether videos play inline or fullscreen in an HTML5 player on iOS. Valid values are:
0: This value causes fullscreen playback. This is currently the default value, though the default is subject to change.
1: This value causes inline playback for UIWebViews created with the allowsInlineMediaPlayback property set to TRUE.
el
This parameter indicates whether the player should show related videos when playback of the initial video ends. Supported values are 0 and 1. The default value is 1.
showinfo
Supported values are 0 and 1.
Setting the parameter's value to 0 causes the player to not display information like the video title and uploader before the video starts playing.
If the player is loading a playlist, and you explicitly set the parameter value to 1, then, upon loading, the player will also display thumbnail images for the videos in the playlist. Note that this functionality is only supported for the AS3 player.
start
This parameter causes the player to begin playing the video at the given number of seconds from the start of the video. The parameter value is a positive integer. Note that similar to the seekTo function, the player will look for the closest keyframe to the time you specify. This means that sometimes the play head may seek to just before the requested time, usually no more than around two seconds.
This document explains how to embed a YouTube player in your application and also defines the parameters that are available in the YouTube embedded player.
By appending parameters to the IFrame URL, you can customize the playback experience in your application. For example, you can automatically play videos using the autoplay parameter or cause a video to play repeatedly using the loop parameter. You can also use the enablejsapi parameter to enable the player to be controlled via the IFrame Player API.
This page currently defines all parameters supported in any YouTube embedded player. Each parameter definition identifies the players that support the corresponding parameter.
Embedded players must have a viewport that is at least 200px by 200px. If the player displays controls, it must be large enough to fully display the controls without shrinking the viewport below the minimum size. We recommend 16:9 players be at least 480 pixels wide and 270 pixels tall.
Embed a YouTube player
You can use any of the following methods to embed a YouTube player in your application and specify player parameters. Note that the instructions below demonstrate how to embed a player that loads a single video. The following section explains how to configure your player to load other types of content, such as playlists and search results.
Embed a player using an <iframe> tag
Define an <iframe> tag in your application in which the src URL specifies the content that the player will load as well as any other player parameters you want to set. The <iframe> tag's height and width parameters specify the dimensions of the player.
If you create the <iframe> element yourself (rather than using the IFrame Player API to create it), you can append player parameters directly to the end of the URL. The URL has the following format:
https://www.youtube.com/embed/VIDEO_ID
The <iframe> tag below would load a 640x360px player that would play the YouTube video M7lc1UVf-VE. Since the URL sets the autoplay parameter to 1, the video would play automatically once the player has loaded.
<iframe id="ytplayer" type="text/html" width="640" height="360"
src="https://www.youtube.com/embed/M7lc1UVf-VE?autoplay=1&origin=http://example.com"
frameborder="0"></iframe>
Embed a player using the IFrame Player API
Follow the IFrame Player API instructions to insert a video player in your web page or application after the Player API's JavaScript code has loaded. The second parameter in the constructor for the video player is an object that specifies player options. Within that object, the playerVars property identifies player parameters.
The HTML and JavaScript code below shows a simple example that inserts a YouTube player into the page element that has an id value of ytplayer. The onYouTubePlayerAPIReady() function specified here is called automatically when the IFrame Player API code has loaded. This code does not define any player parameters and also does not define other event handlers.
<div id="ytplayer"></div>
<script>
// Load the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// Replace the 'ytplayer' element with an <iframe> and
// YouTube player after the API code downloads.
var player;
function onYouTubePlayerAPIReady() {
player = new YT.Player('ytplayer', {
height: '360',
width: '640',
videoId: 'M7lc1UVf-VE'
});
}
</script>
Select content to play
You can configure your embedded player to load a video, a playlist, a user's uploaded videos, or search results for a particular query.
The following list explains these options:
Loading a video
For an IFrame embed, the YouTube video ID for the video that you want to load is specified in the IFrame's src URL.
https://www.youtube.com/embed/VIDEO_ID
If you are using the YouTube Data API (v3), you can programmatically construct these URLs by retrieving video IDs from search results, playlist item resources, video resources, or other resources. After obtaining a video ID, replace the VIDEO_ID text in the URLs above with that value to create the player URL.
Loading a playlist
Set the listType player parameter to playlist. In addition, set the list player parameter to the YouTube playlist ID that you want to load.
https://www.youtube.com/embed?listType=playlist&list=PLAYLIST_ID
Note that you need to prepend the playlist ID with the letters PL as shown in the following example:
https://www.youtube.com/embed?listType=playlist&list=PLC77007E23FF423C6
If you are using the YouTube Data API (v3), you can programmatically construct these URLs by retrieving playlist IDs from search results, channel resources, or activity resources. After obtaining a playlist ID, replace the PLAYLIST_ID text in the URL above with that value.
Loading a user's uploaded videos
Set the listType player parameter to user_uploads. In addition, set the list player parameter to the YouTube username whose uploaded videos you want to load.
https://www.youtube.com/embed?listType=user_uploads&list=USERNAME
Loading search results for a specified query
Set the listType player parameter to search. In addition, set the list player parameter to the query term for which you want the player to load search results.
Parameters
autoplay
This parameter specifies whether the initial video will automatically start to play when the player loads. Supported values are 0 or 1. The default value is 0.
cc_load_policy
Setting the parameter's value to 1 causes closed captions to be shown by default, even if the user has turned captions off. The default behavior is based on user preference.
color
This parameter specifies the color that will be used in the player's video progress bar to highlight the amount of the video that the viewer has already seen. Valid parameter values are red and white, and, by default, the player uses the color red in the video progress bar. See the YouTube API blog for more information about color options.
Note: Setting the color parameter to white will disable the modestbranding option.
controls
This parameter indicates whether the video player controls are displayed. For IFrame embeds that load a Flash player, it also defines when the controls display in the player as well as when the player will load. Supported values are:
controls=0 – Player controls do not display in the player. For IFrame embeds, the Flash player loads immediately.
controls=1 (default) – Player controls display in the player. For IFrame embeds, the controls display immediately and the Flash player also loads immediately.
controls=2 – Player controls display in the player. For IFrame embeds, the controls display and the Flash player loads after the user initiates the video playback.
Note: The parameter values 1 and 2 are intended to provide an identical user experience, but controls=2 provides a performance improvement over controls=1 for IFrame embeds. Currently, the two values still produce some visual differences in the player, such as the video title's font size. However, when the difference between the two values becomes completely transparent to the user, the default parameter value may change from 1 to 2.
disablekb
Setting the parameter's value to 1 causes the player to not respond to keyboard controls. The default value is 0, which means that keyboard controls are enabled. Currently supported keyboard controls are:
Spacebar or [k]: Play / Pause
Arrow Left: Jump back 5 seconds in the current video
Arrow Right: Jump ahead 5 seconds in the current video
Arrow Up: Volume up
Arrow Down: Volume Down
[f]: Toggle full-screen display
[j]: Jump back 10 seconds in the current video
[l]: Jump ahead 10 seconds in the current video
[m]: Mute or unmute the video
[0-9]: Jump to a point in the video. 0 jumps to the beginning of the video, 1 jumps to the point 10% into the video, 2 jumps to the point 20% into the video, and so forth.
enablejsapi
Setting the parameter's value to 1 enables the player to be controlled via IFrame or JavaScript Player API calls. The default value is 0, which means that the player cannot be controlled using those APIs.
For more information on the IFrame API and how to use it, see the IFrame API documentation. (The JavaScript Player API has already been deprecated.)
end
This parameter specifies the time, measured in seconds from the start of the video, when the player should stop playing the video. The parameter value is a positive integer.
Note that the time is measured from the beginning of the video and not from either the value of the start player parameter or the startSeconds parameter, which is used in YouTube Player API functions for loading or queueing a video.
fs
Setting this parameter to 0 prevents the fullscreen button from displaying in the player. The default value is 1, which causes the fullscreen button to display.
hl
Sets the player's interface language. The parameter value is an ISO 639-1 two-letter language code or a fully specified locale. For example, fr and fr-ca are both valid values. Other language input codes, such as IETF language tags (BCP 47) might also be handled properly.
The interface language is used for tooltips in the player and also affects the default caption track. Note that YouTube might select a different caption track language for a particular user based on the user's individual language preferences and the availability of caption tracks.
iv_load_policy
Setting the parameter's value to 1 causes video annotations to be shown by default, whereas setting to 3 causes video annotations to not be shown by default. The default value is 1.
list
The list parameter, in conjunction with the listType parameter, identifies the content that will load in the player.
If the listType parameter value is search, then the list parameter value specifies the search query.
If the listType parameter value is user_uploads, then the list parameter value identifies the YouTube channel whose uploaded videos will be loaded.
If the listType parameter value is playlist, then the list parameter value specifies a YouTube playlist ID. In the parameter value, you need to prepend the playlist ID with the letters PL as shown in the example below.
https://www.youtube.com/embed?
listType=playlist
&list=PLC77007E23FF423C6
Note: If you specify values for the list and listType parameters, the IFrame embed URL does not need to specify a video ID.
listType
The listType parameter, in conjunction with the list parameter, identifies the content that will load in the player. Valid parameter values are playlist, search, and user_uploads.
If you specify values for the list and listType parameters, the IFrame embed URL does not need to specify a video ID.
loop
In the case of a single video player, a setting of 1 causes the player to play the initial video again and again. In the case of a playlist player (or custom player), the player plays the entire playlist and then starts again at the first video.
Supported values are 0 and 1, and the default value is 0.
Note: This parameter has limited support in the AS3 player and in IFrame embeds, which could load either the AS3 or HTML5 player. Currently, the loop parameter only works in the AS3 player when used in conjunction with the playlist parameter. To loop a single video, set the loop parameter value to 1 and set the playlist parameter value to the same video ID already specified in the Player API URL:
https://www.youtube.com/v/VIDEO_ID?
version=3
&loop=1
&playlist=VIDEO_ID
modestbranding
This parameter lets you use a YouTube player that does not show a YouTube logo. Set the parameter value to 1 to prevent the YouTube logo from displaying in the control bar. Note that a small YouTube text label will still display in the upper-right corner of a paused video when the user's mouse pointer hovers over the player.
origin
This parameter provides an extra security measure for the IFrame API and is only supported for IFrame embeds. If you are using the IFrame API, which means you are setting the enablejsapi parameter value to 1, you should always specify your domain as the origin parameter value.
playlist
This parameter specifies a comma-separated list of video IDs to play. If you specify a value, the first video that plays will be the VIDEO_ID specified in the URL path, and the videos specified in the playlist parameter will play thereafter.
playsinline
This parameter controls whether videos play inline or fullscreen in an HTML5 player on iOS. Valid values are:
0: This value causes fullscreen playback. This is currently the default value, though the default is subject to change.
1: This value causes inline playback for UIWebViews created with the allowsInlineMediaPlayback property set to TRUE.
el
This parameter indicates whether the player should show related videos when playback of the initial video ends. Supported values are 0 and 1. The default value is 1.
showinfo
Supported values are 0 and 1.
Setting the parameter's value to 0 causes the player to not display information like the video title and uploader before the video starts playing.
If the player is loading a playlist, and you explicitly set the parameter value to 1, then, upon loading, the player will also display thumbnail images for the videos in the playlist. Note that this functionality is only supported for the AS3 player.
start
This parameter causes the player to begin playing the video at the given number of seconds from the start of the video. The parameter value is a positive integer. Note that similar to the seekTo function, the player will look for the closest keyframe to the time you specify. This means that sometimes the play head may seek to just before the requested time, usually no more than around two seconds.
No comments:
Post a Comment