there is a requirement that the video will be played automatically by pressing the button for a long time. At first, I found that I would report play () failed because the user didn"t interact with the document first all the time. I found a problem and said that in order to avoid random noise caused by the tag, just mute video with a muted, but I don"t want to mute any solution
.related codes
/ / < video id= "video1" width= "320" height= "240" controls muted >
<source src="1.mp4" type="video/mp4">
</video>
<button class="button1">1</button>
<script>
window.onload = function () {
var myVid=document.getElementById("video1");
var box = document.querySelector(".button1");
box.addEventListener("touchstart",function (e) {
// console.log("start");
myVid.play();
myVid.muted = false
});
box.addEventListener("touchmove",function (e) {
console.log("move");
console.log(e);
});
box.addEventListener("touchend",function (e) {
console.log("end");
console.log(e);
myVid.pause();
});
}
</script>