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();
Advertisement
Answer
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.