I have a question with the following code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Video</title>
<script type="text/javascript">
function iniciar() {
video=document.getElementById('video');
video.addEventListener('ended',reproducir,false);
}
function reproducir() {
video.setAttribute('src', 'musica2.mp4')
}
window.addEventListener('load',iniciar,false);
</script>
</head>
<body>
<section>
<video controls autoplay muted id="video" width="720" height="400"
c src="musica.mp4">
</video>
</section>
</body>
</html>
If I remove the muted attribute from the 'video' tag, it no longer plays this when the page is loaded (the autoplay attribute doesn't work). Why is this, and how can I make the video play when the page loads?
Google decided that it was annoying that, when entering a web page, a video could play automatically. So Chrome is pretty restrictive about it . Automatic translation of the web:
You could try to play it automatically using Javascript when the page loads.
It would be something like this:
HTML:
JavaScript:
Cheers!
mmm... I'm not an expert on the matter, but the only thing missing from the code for autoplay to run is to include a complete url in the "src" attribute. Being incomplete does not load the video and without loading there is no play.
Personal note : I use the autoplay attribute in the following way: autoplay="autoplay" and I recommend including the full url inside the "src" attribute at all times, regardless of whether the video is in the same root folder.