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

首頁 > 語言 > JavaScript > 正文

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

2024-05-06 16:05:29
字體:
來源:轉載
供稿:網友
寫了個html5播放視頻的video控件,只支持mp4和3gp(android和ios默認支持的格式就寫了這個) ,需要的朋友可以參考下

復制代碼 代碼如下:


<!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></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 controls "; //根據設置的屬性的值,拼寫video控件
str += " " + _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>

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 北宁市| 措勤县| 张家港市| 比如县| 黑河市| 东海县| 商都县| 冕宁县| 惠水县| 凌海市| 永吉县| 茂名市| 肇庆市| 长子县| 宣武区| 塔城市| 禹城市| 芜湖市| 朔州市| 东莞市| 酒泉市| 吴川市| 锡林郭勒盟| 包头市| 海丰县| 临沧市| 四会市| 雅安市| 乌鲁木齐县| 米易县| 贡山| 仙游县| 凤台县| 磴口县| 静宁县| 沙坪坝区| 新干县| 鹤山市| 宁强县| 乐东| 宁波市|