amp-video

Edit on Github
Open in Playground

Introduction

Embed videos into your AMP HTML files. Video source files should 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.

Example

Your browser doesn't support HTML5 video.

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

Example

Your browser doesn't support HTML5 video.

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

HLS

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.

Example

Your browser doesn't support HTML5 video.

<amp-video width="480"
  height="270"
  poster="/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="/video/tokyo.m3u8">
  <source type="video/mp4"
    src="/video/tokyo-no-hls.mp4">
</amp-video>

Customize 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.

Example

<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.

Example

Rotate for fullscreen

Your browser doesn't support HTML5 video.

<amp-video width="480"
  height="270"
  src="/video/tokyo.mp4"
  poster="/img/tokyo.jpg"
  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>
  <source type="video/webm"
    src="/video/tokyo.webm">
</amp-video>