国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

一個html5播放視頻的video控件只支持android的默認格式mp4和3gp

2019-11-20 20:42:50
字體:
來源:轉載
供稿:網友
復制代碼 代碼如下:

<!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>

//因js水平有限,不喜勿噴,全當沒事看看,video是html5中的新控件,大家可以看看

<script type="text/javascript">

//mp4是ios、android普遍支持的格式
function playVideo(opt) {
if (typeof (opt) == "undefined") {
alert("請傳入必要參數!");
return;
}
if (typeof (opt.elemt) == "undefined") {
alert("請指定播放器要插入的對象!");
return;
}
if (typeof (opt.src) == "undefined") {
alert("請指定要播放視頻的路徑!");
return;
}
var _this = this;
_this.elemt = opt.elemt; //播放器要插入的對象
_this.src = opt.src; //視頻的URL(必設)
_this.width = opt.width > 0 ? opt.width + "px" : "100%"; //寬度(默認100%)
_this.height = opt.height > 0 ? opt.height + "px" : "100%"; //高度(默認100%)
_this.autoplay = opt.autoplay == "true" ? "autoplay" : ""; //自動播放(true為自動播放)
_this.poster = opt.poster; //視頻封面,播放時的封面圖片
_this.preload = opt.preload == "true" ? "preload" : ""; //預加載(true時啟動加載)
_this.loop = opt.loop == "true" ? "loop" : ""; //循環播放(true時循環播放)
var str = "<video id='playVideo' controls "; //根據設置的屬性的值,拼寫video控件
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; //將str放到要插入的對象中
}
playVideo({
//所有參數,elemt和src為必填其他看需求怎么要求
//elemt為播放控件要插入的容器,src為視頻文件地址,preload為預加載,autoplay是否頁面進入就自動播放
//poster為播放前的遮照圖片,loop為是否循環播放,width和heigth默認100%
elemt: document.getElementById("divVideo"),
src: "3.mp4",
preload: "true",
autoplay: "true",
poster: "",
loop: "true",
width: "",
heigth:""
});
</script>
</body>
</html>
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 海宁市| 东乡族自治县| 乳山市| 内乡县| 大田县| 永顺县| 平舆县| 怀安县| 冕宁县| 定陶县| 论坛| 蓝山县| 浦江县| 聊城市| 定安县| 巢湖市| 南漳县| 北宁市| 巫溪县| 濮阳县| 汤阴县| 新晃| 洪湖市| 苗栗市| 和静县| 盐边县| 永平县| 绥中县| 玉溪市| 安国市| 句容市| 广昌县| 淮阳县| 安西县| 衡阳县| 榕江县| 吕梁市| 横山县| 高淳县| 建水县| 大新县|