Autoplay does not play the video

1

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 to the 'video' tag, it will not play this when the page is loaded (the autoplay attribute does not work). What is this about, and how could I get the video to play when the page loads.

    
asked by Frnk 11.06.2018 в 13:50
source

2 answers

4

Google decided that it was annoying that, when entering a web page, a video could be played automatically. So Chrome is quite restrictive about it . Automatic translation of the web:

  

As you may have noticed, web browsers are adopting policies of   automatic reproduction to improve the experience of the   user, minimize the incentives to install blockers   announcements and reduce the consumption of data in expensive networks and / or   restricted. These changes are intended to give greater control of   the reproduction to the users and benefit the editors with cases   of legitimate use.

     

Chrome's automatic playback policies are simple:

     
  • Muted autoplay is always allowed .
  •   
  • Autoplay with sound is allowed if:      
    • The user has interacted with the domain (click, tap, etc.).
    •   
    • On the desktop, the Interaction Index threshold has been crossed with the user's media, which means that the   user has already played video with sound.
    •   
    • On mobile devices, the user has added the site to their home screen.
    •   
  •   
  • Top frames can delegate autoplay permission to their iframes to allow automatic playback with   sound.
  •   

Index of interaction with the media (MEI, of Media Engagement Index )

     

The MEI measures the propensity of an individual to consume media in a   site. Chrome's current focus is a proportion of visits to   significant media reproduction events by origin:

     
  • Media consumption (audio / video) must be greater than 7 seconds.
  •   
  • Audio must be present and not muted.
  •   
  • The tab with video is active.
  •   
  • The size of the video (in px) must be greater than 200x140.
  •   

From that, Chrome calculates a participation score of   media that is higher in the sites where the media are reproduced   periodic form. When it is high enough, the reproduction   Multimedia can only be played automatically on the desktop.

     

The user's MEI is available on the internal page chrome://media-engagement .

    
answered by 11.06.2018 / 14:00
source
1

You could try to reproduce it automatically using Javascript when you load the page.

It would be something like this:

HTML:

<video id="video" width="720" height="400" src=".../.mp4">

Javascript:

(function() {
  let vid = document.getElementById("video"); 

  function playVid() { 
    vid.play(); 
  } 

  function pauseVid() { 
    vid.pause(); 
  }
})();

Greetings!

    
answered by 11.06.2018 в 14:05