Atributo autoplay de HTML
The HTML autoplay specifies that the audio or video will start playing automatically as soon as possible. See how to use it on the <audio> and <video> elements.
El atributo autoplay de HTML es un atributo booleano que especifica que el audio o el video comenzará a reproducirse automáticamente tan pronto como sea posible.
Puedes usar este atributo en los siguientes elementos: <audio> y <video>.
Sintaxis
<tag autoplay></tag>Nota: Los navegadores modernos restringen la reproducción automática (
autoplay) para medios con pistas de audio. Para garantizar que funcione, también debes incluir el atributomuteden el elemento.
Ejemplo del atributo autoplay de HTML utilizado en el elemento <audio>:
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
</head>
<body>
<audio controls autoplay>
<source src="/build/audios/jingle_bells.ogg" type="audio/ogg" />
<source src="/build/audios/audio.mp3" type="audio/mpeg" />
</audio>
<p>Click the play button</p>
</body>
</html>Ejemplo del atributo autoplay de HTML utilizado en el elemento <video>:
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
</head>
<body>
<video width="320" height="240" controls autoplay muted>
<source src="http://techslides.com/demos/sample-videos/small.ogv" type="video/ogg" />
<source src="/build/videos/arcnet.io(7-sec).mp4" type="video/mp4" />
</video>
<p>Some information about video</p>
</body>
</html>Práctica
Práctica
¿Cuál es el uso correcto del atributo 'autoplay' en HTML?