I tried making an alternative for autoplay video.
It works fine on desktop but still needs a tap on mobile. Atleast on my Samsung Galaxy Express and Chrome I just tried.
Idea was/is to make button display:none if autoplay is working well enough.
So I have Html video with play/pause button triggered with JS. And to make an autoplay I simulated the click function.
The click onLoad seems to kind of happen because it looks like a pause button when loading the page. But the video is not playing before tapping.
I do know HTML5 Video autoplay is not supported by mobile. I also know there have been similar questions. But know I would like to understand what is going on with the JS. And ofcourse would not mind a solution for autoplay mobile.
Here is my code.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Js Philosophy</title>
<script type="text/javascript">
function ClickButton()
{
document.getElementById('play').click();
}
</script>
</head>
<body onload="ClickButton()">
<script type="text/javascript">
function vidplay() {
var video = document.getElementById("Video1");
var button = document.getElementById("play");
if (video.paused) {
video.play();
button.textContent = "||";
} else {
video.pause();
button.textContent = ">";
}
}
</script>
<div >
<video id="Video1" width="100%" poster="/video/thumb1.jpg">
<source src="/video/peakvideo.mp4" type="video/mp4" />
<source src="/video/peakvideo2.mp4" type="video/mp4" />
<source src="/video/peakvideo.webm" type="video/webm" />
<source src="/video/peakvideo.ogv" type="video/ogv" />
not supported
</video>
<div id="buttonbar" class="">
<button id="play" onclick="vidplay()">></button>
</div>
</div>
<div class="main">Ur stuff beginsss here under</div>
</div>
</body>
</html>