Copy codeThe Code 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>
// Due to limited js levels, don't like it or not. It's okay to check it out. video is a new control in html5. You can check it out.
<Script type = "text/javascript">
// Mp4 is a common format supported by ios and android
Function playVideo (opt ){
If (typeof (opt) = "undefined "){
Alert ("Please input required parameters! ");
Return;
}
If (typeof (opt. elemts) = "undefined "){
Alert ("specify the object to be inserted in the player! ");
Return;
}
If (typeof (opt. src) = "undefined "){
Alert ("specify the path of the video to be played! ");
Return;
}
Var _ this = this;
_ This. elemts = opt. elemts; // the object to be inserted by the player.
_ This. src = opt. src; // video URL (required)
_ This. width = opt. width> 0? Opt. width + "px": "100%"; // width (100% by default)
_ This. height = opt. height> 0? Opt. height + "px": "100%"; // height (100% by default)
_ This. autoplay = opt. autoplay = "true "? "Autoplay": ""; // automatic playback (true indicates automatic playback)
_ This. poster = opt. poster; // specifies the video album art and the album art during playback.
_ This. preload = opt. preload = "true "? "Preload": ""; // pre-load (start loading when true)
_ This. loop = opt. loop = "true "? "Loop": ""; // loop playback (when true, loop playback)
Var str = "<video id = 'playvideo' controls"; // spell the video control based on the set attribute value.
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, elemts 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, and autoplay is automatically played when the page is accessed
// Poster indicates the picture that is taken before playback, loop indicates whether to play cyclically, and width and heigth are 100% by default.
Elemt: document. getElementById ("divVideo "),
Src: "3.mp4 ",
Preload: "true ",
Autoplay: "true ",
Poster :"",
Loop: "true ",
Width :"",
Heigth :""
});
</Script>
</Body>
</Html>