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>
이 페이지의 설명만으로 궁금한 점이 모두 해결되지 않는다면 다른 AMP 사용자에게 문의하여 구체적인 활용 사례를 논의해 보세요.
Stack Overflow로 이동 설명이 부족한 기능을 발견하셨나요?AMP 프로젝트는 여러분의 참여와 기여를 적극 환영합니다! 오픈 소스 커뮤니티를 통해 지속적으로 활동해 주셔도 좋지만 관심 있는 주제에 한 번만 기여하셔도 큰 도움이 됩니다.
GitHub에서 샘플 수정하기-
Written by @sebastianbenz