国产探花免费观看_亚洲丰满少妇自慰呻吟_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>
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 泽库县| 贺兰县| 阳江市| 宁陵县| 涿鹿县| 建始县| 天津市| 斗六市| 南部县| 四会市| 宣武区| 武清区| 鄯善县| 西峡县| 榕江县| 酒泉市| 灵丘县| 青川县| 庄浪县| 康乐县| 本溪市| 军事| 新竹县| 武宣县| 林州市| 额尔古纳市| 明光市| 洛南县| 正阳县| 湟中县| 朝阳县| 太康县| 尼玛县| 澎湖县| 凉山| 汉沽区| 博兴县| 玉门市| 禹州市| 务川| 探索|