The code copy is as follows:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<div id="divVideo"></div>
//Because the level of js is limited, don't criticize if you don't like it. Just pretend that it's okay. Video is a new control in html5. You can check it out.
<script type="text/javascript">
//mp4 is a format commonly supported by iOS and Android
function playVideo(opt) {
if (typeof (opt) == "undefined") {
alert("Please pass in the necessary parameters!");
return;
}
if (typeof (opt.elemt) == "undefined") {
alert("Please specify the object to be inserted by the player!");
return;
}
if (typeof (opt.src) == "undefined") {
alert("Please specify the path to play the video!");
return;
}
var _this = this;
_this.elemt = opt.elemt; //The object to be inserted by the player
_this.src = opt.src; //The URL of the video (required)
_this.width = opt.width > 0 ? opt.width + "px" : "100%"; //Width (default 100%)
_this.height = opt.height > 0 ? opt.height + "px" : "100%"; //Height (default 100%)
_this.autoplay = opt.autoplay == "true" ? "autoplay" : ""; //Autoplay (true is automatic playback)
_this.poster = opt.poster; //Video cover, cover picture during playback
_this.preload = opt.preload == "true" ? "preload" : ""; //Preload (start loading when true)
_this.loop = opt.loop == "true" ? "loop" : ""; //Loop play (loop plays when true)
var str = "<video id='playVideo' controls "; //Spelling the video control based on the value of the set attribute
str += " width='" + _this.width + "' height='" + _this.height + "' " + _this.autoplay + " " + _this.preload + " " + _this.loop + " ";
if (typeof (_this.poster) != "undefined") {
str += " poster='" + _this.poster + "' >";
} else {
str += " > ";
}
str += " <source src='" + _this.src + "' />";
str += "</video>";
this.elemt.innerHTML = str; //Put str into the object to be inserted
}
playVideo({
//All parameters, elemt and src are required to fill in other parameters, depending on the requirements
//elemt is the container to be inserted in the playback control, src is the video file address, preload is preload, and if the autoplay page enters, it will automatically play
//Poster is the occluded picture before playback, loop is whether to play loop, width and heigth are 100% by default
elemt: document.getElementById("divVideo"),
src: "3.mp4",
preload: "true",
autoplay: "true",
poster: "",
loop: "true",
width: "",
height:""
});
</script>
</body>
</html>