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

首頁 > 編程 > HTML > 正文

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

2020-03-24 16:01:46
字體:
供稿:網(wǎng)友
JavaScript 一個html5播放視頻的video控件只支持android的默認格式mp4和3gp
復(fù)制代碼 代碼如下:
!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水平有限,不喜勿噴,全當(dāng)沒事看看,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(必設(shè))
_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" : ""; //預(yù)加載(true時啟動加載)
_this.loop = opt.loop == "true" ? "loop" : ""; //循環(huán)播放(true時循環(huán)播放)
var str = " video id='playVideo' controls "; //根據(jù)設(shè)置的屬性的值,拼寫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為預(yù)加載,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
更多編程語言

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 碌曲县| 丰镇市| 梨树县| 剑河县| 齐齐哈尔市| 红原县| 西宁市| 高州市| 嘉兴市| 蒙自县| 江北区| 鸡西市| 桓仁| 海南省| 积石山| 平原县| 江陵县| 社旗县| 洪湖市| 兴安县| 仁化县| 洪雅县| 菏泽市| 鲁山县| 香港| 乐昌市| 湖北省| 宾阳县| 罗源县| 谷城县| 西宁市| 太和县| 昌吉市| 昌乐县| 页游| 麟游县| 油尖旺区| 苗栗县| 晴隆县| 资兴市| 依安县|