Mastering the Media: Complete HTML Course
Sobre a Aula

Audio Autostart with Audio Element

When it comes to incorporating audio into your web pages, you can set up automatic playback using the autoplay attribute in the <audio> element.

Check out this example:

<audio controls autoplay>
  <source src="horse.ogg" type="audio/ogg">
  <source src="horse.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>

However, it is important to keep in mind that automatic playback may be restricted in some browsers, especially those based on Chromium, such as Google Chrome.

Generally, these browsers do not allow automatic playback in many cases unless the playback is muted.

By adding the autoplay attribute to the <audio> element, you instruct the browser to automatically start playing the audio file as soon as the page is loaded.

This can provide a more engaging experience for users, eliminating the need to click on a play button.

It is crucial to be aware that Chromium-based browsers, like Google Chrome, often impose restrictions on automatic playback.

This means that, in most cases, default autoplay may not work as expected. However, there is an interesting exception.

To circumvent automatic playback restrictions in Chromium browsers, such as Google Chrome, you can adopt muted autoplay.

This means that the audio will play automatically but without sound. To implement this, you can add the muted and autoplay attributes to the <audio> element. This approach is generally accepted, even in more restrictive environments.

By understanding these nuances related to automatic audio playback in HTML, you can create a more personalized experience for visitors to your site while ensuring compliance with modern browser autoplay policies.

Entrar na conversa
Rolar para cima