AMP
  • websites

Rich Media Notifications

Introduction

Media notifications are one of the most common ways users control media playback on mobile devices. Chrome for Android now exposes the MediaSessionAPI to let developers customize the appearance of notifications that show up when an audio/video is playing.

amp-video, amp-audio and other AMP video players now implement the MediaSessionAPI and let yo effortlessly show better notifications for media playback on mobile devices.

Since notifications are synced across devices, implementing the MediaSessionAPI once will let your users see richer information about the media file currently playing as well as pause it / play it from their notification center, lock screen or even smartwatch!

Setup

Depending on whether you're implementing custom media notifications for amp-video,...

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

... amp-audio or other video players, import the necessary components.

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

Markup

If you are using a video player that already implements the internal MediaSessionAPI like amp-youtube, then your work is done! The player will handle the notifications, add artwork and metadata based on the information it has on its servers.

For amp-audio and amp-video, we need to provide more information to add to the media notification.

Specify the artist, artwork, title and album by adding each of the attributes to the amp-audio / amp-video element.

To try the examples, you have to be on Chrome for Android.

Start playing the audio/video then notice how the notification on your device or smartwatch has all the information/artwork specified here

For audio playback with amp-audio

A sample amp-audio component with media notifications:

<amp-audio src="https://storage.googleapis.com/media-session/sintel/snow-fight.mp3" artwork="https://storage.googleapis.com/media-session/sintel/artwork-512.png" title="Snow Fight" album="Jan Morgenstern" artist="Sintel" height="50" width="auto" controls>
</amp-audio>

This is what it looks like on a mobile device:

For video playback with amp-video

in this example, we provide both poster and artwork.

poster serves as a placeholder shown to users while the video loads, while artwork is the image that appears in the rich notifications (usually a square image of 500 by 500 pixels).

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

This what it looks like on a mobile device:

...and on an Android smartwatch:

자세한 설명이 필요하신가요?

이 페이지의 설명만으로 궁금한 점이 모두 해결되지 않는다면 다른 AMP 사용자에게 문의하여 구체적인 활용 사례를 논의해 보세요.

Stack Overflow로 이동
설명이 부족한 기능을 발견하셨나요?

AMP 프로젝트는 여러분의 참여와 기여를 적극 환영합니다! 오픈 소스 커뮤니티를 통해 지속적으로 활동해 주셔도 좋지만 관심 있는 주제에 한 번만 기여하셔도 큰 도움이 됩니다.

GitHub에서 샘플 수정하기