AMP

Important: this documentation is not applicable to your currently selected format stories!

amp-youtube

 
You can now use this component outside valid AMP documents using the Bento version of this component. Learn more in the Bento guide.

Description

Displays a YouTube video.

 

Required Scripts

<script async custom-element="amp-youtube" src="https://cdn.ampproject.org/v0/amp-youtube-0.1.js"></script>

Usage

Displays a YouTube video.

With the responsive layout, the width and height from the example should yield correct layouts for 16:9 aspect ratio videos:

<amp-youtube
  data-videoid="mGENRKrdoGY"
  layout="responsive"
  width="480"
  height="270"
></amp-youtube>
<amp-youtube
  id="myLiveChannel"
  data-live-channelid="UCB8Kb4pxYzsDsHxzBfnid4Q"
  width="358"
  height="204"
  layout="responsive"
>
  <amp-img
    src="https://i.ytimg.com/vi/Wm1fWz-7nLQ/hqdefault_live.jpg"
    placeholder
    layout="fill"
  />
</amp-youtube>

Attributes

autoplay

If this attribute is present, and the browser supports autoplay:

  • the video is automatically muted before autoplay starts
  • when the video is scrolled out of view, the video is paused
  • when the video is scrolled into view, the video resumes playback
  • when the user taps the video, the video is unmuted
  • if the user has interacted with the video (e.g., mutes/unmutes, pauses/resumes, etc.), and the video is scrolled in or out of view, the state of the video remains as how the user left it. For example, if the user pauses the video, then scrolls the video out of view and returns to the video, the video is still paused.

loop

If this attribute is present, the video or playlist will play again (from the beginning) once it ends.

data-videoid

The YouTube video id found in every YouTube video page URL.

For example, in this URL: https://www.youtube.com/watch?v=Z1q71gFeRqM, Z1q71gFeRqM is the video id.

data-live-channelid

The Youtube channel id that provides a stable livestream url. For example, in this URL: https://www.youtube.com/embed/live_stream?channel=UCB8Kb4pxYzsDsHxzBfnid4Q, UCB8Kb4pxYzsDsHxzBfnid4Q is the channel id. You can provide a data-live-channelid instead of a data-videoid attribute to embed a stable url for a live stream instead of a video. Channels do not come with default placeholders. You can provide a placeholder for the video per example 2 above.

data-param-*

All data-param-* attributes (with the exception of data-param-autoplay and data-param-loop) will be added as query parameter to the YouTube iframe src. This may be used to pass custom values through to YouTube plugins, such as whether to show controls.

Keys and values will be URI encoded. Keys will be camel cased

data-param-controls=1 becomes &controls=1

See YouTube Embedded Player Parameters for more parameter options for YouTube.

Use the autoplay attribute instead of data-param-autoplay and the loop attribute instead of data-param-loop since both the autoplay and looping behaviors are handled internally by AMP instead of the Youtube player.

dock

Requires amp-video-docking component. If this attribute is present and the video is playing manually, the video will be "minimized" and fixed to a corner or an element when the user scrolls out of the video component's visual area.

credentials (optional)

Defines a credentials option as specified by the Fetch API.

  • Supported values: omit, include
  • Default: include

If you want to use the YouTube player in privacy-enhanced mode, pass the value of omit.

Usually YouTube sets its cookies when the player is loaded. In privacy-enhanced mode cookies are set when the user has clicked on the player.

title (optional)

Define a title attribute for the component to propagate to the underlying <iframe> element. The default value is "YouTube video".

common attributes

This element includes common attributes extended to AMP components.

Validation

See amp-youtube rules in the AMP validator specification.

Требуется дополнительная помощь?

Вы читали этот документ десятки раз, но так и не нашли ответов на все свои вопросы? Возможно, другие люди столкнулись с такой же проблемой — обратитесь к ним на Stack Overflow.

Перейти на Stack Overflow
Нашли ошибку или недостающую функцию?

Проект AMP активно поощряет ваше участие и сотрудничество! Мы надеемся, что вы станете постоянным участником нашего открытого сообщества, но разовые вклады в работу над задачами, которые вам особенно интересны, также приветствуются.

Перейти на GitHub