Force autoplay on video(not mute)

Asked

Viewed 262 times

-1

I’m trying to force an autoplay on videos with javascript, but with videos not mute, with mute video is very simple, but with it with volume works 50%, for example, if I access the video page by clicking another page the autoplay runs, because there was user interference, but in case you are already on the video page and give a F5 the browser reads as something programmed, without user interference and error.

I know this is possible because on Youtube even you giving F5 the video with audio is played automatically, probably there is some event that is allowed this, what I am currently using is briefly the following:

document.addEventListener('DOMContentLoaded',function(e){
  setTimeout(function(){
    document.querySelector('video').play();
  },1000);
});

And the mistake that comes when trying to give the autoplay with video with audio by F5 is the promise:

Uncaught (in promise) DOMException: play() failed because the user didn't interact with the document first. 
  • has already tried using Event Document.ready?

  • 1

    Initially it used jQuery, but then I passed all the scope of video script to pure JS, but with jQuery it was the same result as Domcontentloaded.

  • Well, I don’t know how to help then, but is it really a good idea to start the page with sound? Because if such video is not the main purpose of the page it is usually unpleasant to open a page and start leaving audio without you waiting, especially if you are in a public or work environment (Zap moan that says)

  • 1

    The application I’m doing is from a specific audience, there will be no random videos like Youtube, it was just the same example, but actually already works autoplay but only with clicks and Mousemove, I wanted to see if updating the page or in some other way also give.. like letting the autoplay go round

  • Some browsers block and only allow if the user even click.

1 answer

1

Tail that answer in general stackoverflow. You have to use the onloadeddata event as you may happen to give play without first loading the video.

<video onloadeddata="this.play();this.muted=false;" poster="https://durian.blender.org/wp-content/themes/durian/images/void.png" playsinline loop muted controls>
    <source src="http://grochtdreis.de/fuer-jsfiddle/video/sintel_trailer-480.mp4" type="video/mp4" />
    Your browser does not support the video tag or the file format of this video.
</video>
  • You tried this part this.muted=false; ?

  • Trying this way ai, the video is paused at the time of this.muted=false; and from this message: Unmuting failed and the element was paused Instead because the user didn’t Interact with the Document before.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.