Rich Media Notifications
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-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!
Depending on whether you're implementing custom media notifications for
<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>
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.
amp-video, we need to provide more information to add to the media notification.
album by adding each of the attributes to the
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 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
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 上的示例
Written by @wassgha