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.
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>
Sollten die Erklärungen auf dieser Seite nicht all deine Fragen beantworten, kannst du dich gerne an andere AMP Nutzer wenden, um deinen konkreten Use Case zu besprechen.
Zu Stack Overflow wechseln Ein Feature wurde nicht erklärt?Das AMP Projekt ist auf deine Teilnahme und deine Beiträge angewiesen! Wir hoffen natürlich, dass du dich aktiv an unserer Open Source Community beteiligen wirst. Aber wir freuen uns auch über einmalige Beiträge zu den Themen, die dich besonders interessieren.
Beispiel auf GitHub bearbeiten-
Written by @sebastianbenz