An html5 playback video control only supports android's default formats mp4 and 3gp

  • 2020-03-30 02:53:09
  • OfStack

 
<!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 js level is limited, do not like spray, when all have nothing to see,video is the new control in html5, you can see

<script type="text/javascript"> 

//Mp4 is a commonly supported format for ios and android
function playVideo(opt) { 
if (typeof (opt) == "undefined") { 
alert(" Please pass in the required parameters! "); 
return; 
} 
if (typeof (opt.elemt) == "undefined") { 
alert(" Please specify the object to insert in 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 into the player
_this.src = opt.src; //Video URL(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 for autoplay)
_this.poster = opt.poster; //The cover of the video, the picture of the cover while it is playing
_this.preload = opt.preload == "true" ? "preload" : ""; //Preload (start loading when true)
_this.loop = opt.loop == "true" ? "loop" : ""; //Looping (looping when true)
var str = "<video id='playVideo' controls "; //Depending on the value of the property set, spell the video control
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; //Place STR in the object to be inserted
} 
playVideo({ 
//All parameters, elemt and SRC are required
//Elemt is the container to be inserted into the playback control, SRC is the video file address, preload is the preload, autoplay is automatically played if the page is entered
//Poster is the mask image before playing, loop is whether to loop, width and heigth default 100%
elemt: document.getElementById("divVideo"), 
src: "3.mp4", 
preload: "true", 
autoplay: "true", 
poster: "", 
loop: "true", 
width: "", 
heigth:"" 
}); 
</script> 
</body> 
</html> 

Related articles: