解决微信端手机视频播放兼容性问题

本文详细介绍了如何通过JavaScript自定义实现一个视频播放器,包括选择支持的视频格式、设置播放器属性、添加控制面板等功能。
   <script type="text/javascript">
//mp4是ios、android普遍支持的格式 
function playVideo(opt) {
  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" : "400"; //高度(默认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 : "${url}",
  preload : "true",
  autoplay : "true",
  poster : "",
  loop : "true",
  width : "",
  heigth : "400px"
});
</script>

 

转载于:https://www.cnblogs.com/sprinng/p/4856022.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值