Google AMP amp-audio
Опубликовано: 12 Апреля, 2022

Часто, как разработчик, мы хотим добавить аудиофайл на веб-страницу. Раньше аудио можно было воспроизводить только на веб-страницах с помощью веб-плагинов, таких как Flash. Тег «audio» - это встроенный элемент, который используется для встраивания звуковых файлов на веб-страницу. Это очень полезный тег, если вы хотите добавить на свою веб-страницу аудио, например песни, интервью и т. Д. Чтобы встраивать аудио в страницы AMP, вы должны использовать тег amp-audio.
Setup: To use the amp-audio, you have to import the amp-audio component into the head of the webpage.
HTML
<script async custom-element="amp-audio" </script> |
Атрибуты:
- width: определяет ширину звукового разделения.
- height: определяет высоту звукового разделения.
- src: определяет источник воспроизводимого аудиофайла.
- preload: устанавливает атрибут предварительной загрузки для аудио тега HTML.
- автовоспроизведение: если присутствует, автоматически запускает звук при загрузке страницы.
- приглушено: если присутствует, по умолчанию устанавливает уровень громкости равным 0.
- loop: если присутствует, автоматически повторяет звук от начала, когда он заканчивается.
Example:
HTML
<!doctype html><html amp> <head> <meta charset="utf-8"> <title>Google AMP amp-audio</title> <!-- Import the mandatory script --> <script async src= </script> <script async custom-element="amp-audio" </script> <link rel="canonical" href="geeksforgeeks.html"> <!-- It is mandatory meta tag. --> <meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1"> <!-- Add the following boilerplate tag as it is. --> <style amp-boilerplate> body { -webkit-animation: -amp-start 8s steps(1, end) 0s 1 normal both; -moz-animation: -amp-start 8s steps(1, end) 0s 1 normal both; -ms-animation: -amp-start 8s steps(1, end) 0s 1 normal both; animation: -amp-start 8s steps(1, end) 0s 1 normal both; } @-webkit-keyframes -amp-start { from { visibility: hidden } to { visibility: visible } } @-moz-keyframes -amp-start { from { visibility: hidden } to { visibility: visible } } @-ms-keyframes -amp-start { from { visibility: hidden } to { visibility: visible } } @-o-keyframes -amp-start { from { visibility: hidden } to { visibility: visible } } @keyframes -amp-start { from { visibility: hidden } to { visibility: visible } } </style> <noscript> <style amp-boilerplate> body { -webkit-animation: none; -moz-animation: none; -ms-animation: none; animation: none } </style> </noscript> <!-- This is custom amp-style --> <style amp-custom> h1 { color: green; text-align: center; } </style></head> <body> <h1> Geeks For Geeks </h1> <amp-audio width="auto" height="50" src="GeeksForGeeks.mp3"> <div fallback> Your browser doesn’t support HTML5 audio </div> </amp-audio></body> </html> |
Выход: