A video control that HTML5 play videos only supports the default format of Android mp4 and 3gp_javascript tips

Source: Internet
Author: User
Copy Code code as follows:

<! DOCTYPE html>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title></title>
<body>

<div id= "Divvideo" ></div>

Because JS level is limited, do not like to spray, all when nothing to see, video is the new control in HTML5, we can see

<script type= "Text/javascript" >

MP4 is a widely supported format for 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; objects to be inserted by the viewer
_THIS.SRC = OPT.SRC; The URL of the video (must be set)
_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": ""; Auto Play (True to AutoPlay)
_this.poster = Opt.poster; Video cover, when playing the cover picture
_this.preload = Opt.preload = = "true"? "Preload": ""; Preload (Start loading when true)
_this.loop = Opt.loop = = "true"? "Loop": ""; Loop Play (loop playback true)
var str = "<video id= ' PlayVideo ' controls"; Spelling the video control based on the value of the property being set
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 in the object you want to insert
}
PlayVideo ({
All parameters, ELEMT and SRC are required to fill in others to see how requirements
ELEMT for the playback control to insert the container, src for the video file address, preload for preload, autoplay whether the page entry will automatically play
Poster for the camera before playback, loop for loop playback, width and heigth default 100%
Elemt:document.getElementById ("Divvideo"),
SRC: "3.mp4",
Preload: "true",
AutoPlay: "True",
Poster: "",
Loop: "True",
Width: "",
Heigth: ""
});
</script>
</body>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.