AMP
  • websites

amp-video

Introduction

Use amp-video to embed videos into your AMP HTML files. Video source files must be served via HTTPS.

Setup

Import the amp-video component.

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

Basic usage

A simple video with controller. amp-video supports the following formats: mp4, webm, ogg together with all the formats supported by the HTML5 video tag including HLS.

Your browser doesn't support HTML5 video.

<amp-video width="480" height="270" src="/static/samples/video/tokyo.mp4" poster="/static/samples/img/tokyo.jpg" layout="responsive" controls>
  <div fallback>
    <p>Your browser doesn't support HTML5 video.</p>
  </div>
  <source type="video/mp4" src="/static/samples/video/tokyo.mp4">
  <source type="video/webm" src="/static/samples/video/tokyo.webm">
</amp-video>

Autoplay

Setting autoplay will automatically play/pause the video as it is scrolled into/out of view on supported browsers.

The video is automatically muted before autoplay starts, 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.

Your browser doesn't support HTML5 video.

<amp-video width="720" height="405" src="https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" poster="https://peach.blender.org/wp-content/uploads/bbb-splash.png" layout="responsive" controls autoplay>
  <div fallback>
    <p>Your browser doesn't support HTML5 video.</p>
  </div>
</amp-video>

HLS support

AMP supports adaptive bitrate video via HLS provided it is supported by the browser. (Note that whilst HLS is supported by most mobile browsers—including Chrome and Safari—few desktop browsers support it.)

The videos below have the bitrate burnt into the video files themselves to make it easier to discover when the browser switches between streams. If your browser does not support HLS, you will see "No HLS". If you need to create files in the appropriate format, we recommend investigating shaka packager.

Your browser doesn't support HTML5 video.

<amp-video width="480" height="270" poster="/static/samples/img/tokyo.jpg" layout="responsive" controls autoplay>
  <div fallback>
    <p>Your browser doesn't support HTML5 video.</p>
  </div>
  <source type="application/vnd.apple.mpegurl" src="/static/samples/video/tokyo.m3u8">
  <source type="video/mp4" src="/static/samples/video/tokyo-no-hls.mp4">
</amp-video>

Custom media notifications


With the implementation of the MediaSessionAPI on AMP, you can now show rich notifications that describe the playing media through the artist, album, artwork and title attributes. Learn more by following this tutorial.

<amp-video autoplay src="https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" poster="https://peach.blender.org/wp-content/uploads/bbb-splash.png" artwork="img/bigbuckbunny.jpg" title="Big Buck Bunny" album="Blender" artist="Blender Foundation" width="720" height="405" layout="responsive" controls>
</amp-video>

Rotate to fullscreen

Setting rotate-to-fullscreen will automatically show the video on fullscreen when the user rotates their device into landscape mode, if it's playing manually and visible.

See a more advanced example for displaying a user hint signaling that the device can be rotated to enter fullscreen.

Rotate for fullscreen

Your browser doesn't support HTML5 video.

<amp-video width="720" height="405" src="https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" poster="https://peach.blender.org/wp-content/uploads/bbb-splash.png" layout="responsive" controls rotate-to-fullscreen>
  <div class="video-hint-container" id="video-hint">
    <div class="video-hint">Rotate for fullscreen</div>
  </div>
  <div fallback>
    <p>Your browser doesn't support HTML5 video.</p>
  </div>
</amp-video>
需要进一步说明?

如果此页面上的说明未能涵盖您的所有问题,欢迎与其他 AMP 用户取得联系,讨论您的具体用例。

前往 Stack Overflow
一项无法解释的功能?

AMP 项目强烈鼓励您参与并做出贡献!我们希望您能成为我们开放源代码社区的持续参与者,但我们也欢迎您对所热衷问题做出一次性贡献。

编辑 GitHub 上的示例