<!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.sr
C) == "undefined")
{ alert("请指定要播放视频的路径!"
); return;
}
var _this = this;
_thi
s.elemt = opt.elemt; //播放器要插入的对象
_thi
s.src = opt.sr
c; //视频的URL(必设)
_thi
s.width = opt.width > 0 ? opt.width + "px" : "100%"; //宽度(
默认100%)
_thi
s.height = opt.height > 0 ? opt.height + "px" : "100%"; //高度(
默认100%)
_thi
s.autoplay = opt.autoplay == "true" ? "autoplay" : ""; //
自动播放(true为
自动播放)
_thi
s.poster = opt.poster; //视频封面,播放时的封面
图片 _thi
s.preload = opt.preload == "true" ? "preload" : ""; //
预加载(true时启动加载)
_thi
s.loop = opt.loop == "true" ? "loop" : ""; //循环播放(true时循环播放)
var str = "<video id='playVideo' controls "; //根据设置的
属性的值,拼写video控件
str += " width='" + _thi
s.width + "' height='" + _thi
s.height + "' " + _thi
s.autoplay + " " + _thi
s.preload + " " + _thi
s.loop + " ";
if (typeof (_thi
s.poster)
!= "undefined")
{ str += " poster='" + _thi
s.poster + "' >";
} else
{ str += " > ";
}
str += " <
source src='" + _thi
s.src + "' />";
str += "</video>";
thi
s.elemt.innerHTML = str; //将str放到要插入的对象中
}
playVideo(
{ //所有参数,elemt和src为必填其他看需求怎么要求
//elemt为播放控件要插入的容器,src为视频@L_
674_11@地址,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>