一個html5播放視頻的video控件只支持android的默認格式mp4和3gp
來源:易賢網(wǎng) 閱讀:2789 次 日期:2014-05-09 14:58:28
溫馨提示:易賢網(wǎng)小編為您整理了“一個html5播放視頻的video控件只支持android的默認格式mp4和3gp”,方便廣大網(wǎng)友查閱!

寫了個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 id="divVideo"></div>

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

<script type="text/javascript">

//mp4是ios、android普遍支持的格式

function playVideo(opt) {

if (typeof (opt) == "undefined") {

alert("請傳入必要參數(shù)!");

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" : ""; //循環(huán)播放(true時循環(huán)播放)

var str = "<video id='playVideo' controls "; //根據(jù)設置的屬性的值,拼寫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({

//所有參數(shù),elemt和src為必填其他看需求怎么要求

//elemt為播放控件要插入的容器,src為視頻文件地址,preload為預加載,autoplay是否頁面進入就自動播放

//poster為播放前的遮照圖片,loop為是否循環(huán)播放,width和heigth默認100%

elemt: document.getElementById("divVideo"),

src: "3.mp4",

preload: "true",

autoplay: "true",

poster: "",

loop: "true",

width: "",

heigth:""

});

</script>

</body>

</html>

更多信息請查看IT技術專欄

更多信息請查看網(wǎng)絡編程
關于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 加入群交流 | 手機站點 | 投訴建議
工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務許可證:(云)人服證字(2023)第0102001523號
聯(lián)系電話:0871-65317125(9:00—18:00) 獲取招聘考試信息及咨詢關注公眾號:hfpxwx
咨詢QQ:526150442(9:00—18:00)版權所有:易賢網(wǎng)