0

I have a playlist in javascript, when it is muted the video plays automatically, otherwise it doesn't play automatically.

How can I make autoplay and muted false?

My code HTML is:

<video  id="vid" src="main/" style="width:1360px; height:750px; visibility:visibility;"  controls playsinline     >

var separador = ";";
var video = document.currentScript.parentElement;
var sec = document.getElementById("valor").textContent;
var playlist = sec.split(separador);
video.volume = 0.1;

var lastSong = null;
var selection = null;
var video = document.getElementById("vid");

video.autoplay = true;
video.muted = true;


video.addEventListener("ended", selectRandom);
//video.muted=false;
function selectRandom() {
  while (selection == lastSong) {

    selection = Math.floor(Math.random() * playlist.length);

  }

  lastSong = selection;
  video.src = playlist[selection];

}

selectRandom();
video.play();
  • 1
    You are defining the variable `video` twice - change it to be two separate variables - Also, can you include the HTML into your question? – blurfus Jan 01 '22 at 20:38
  • Does [this](https://stackoverflow.com/questions/60342545/how-can-i-autoplay-a-video-without-muting) answer your question? – Nikita Skrebets Jan 01 '22 at 23:24
  • hi, thanks for answering, it doesn't work changing the variable, it works as long as it is in muted – Misael Malledo Jan 03 '22 at 11:57
  • Thank you very much, it is indeed the autoplay policy. I can solve it by adding the page as a shortcut on the desktop. The objective is to reproduce the videos on screens in a store. – Misael Malledo Jan 03 '22 at 12:16

2 Answers2

1

You can't play a video automatically with sound. There's a thing called "Autoplay Policy", at least for Chrome, but all other browsers are trying to block it.

See more information here.

Ali Demirci
  • 5,302
  • 7
  • 39
  • 66
0

Thank you very much, it is indeed the autoplay policy. I can solve it by adding the page as a shortcut on the desktop. The objective is to reproduce the videos on screens in a store.