视频播放插件Video.js

视频播放插件Video.jsie兼容6

http://www.jq22.com/jquery-info404
 
插件描述:Video.js 是一个通用的在网页上嵌入视频播放器的 JS 库,Video.js 自动检测浏览器对 HTML5 的支持状况,若是不支持 HTML5 则自动使用 Flash 播放器。(要支持ie低版本请下载5.4.3版 )

Video.js最新v5.10.8版 2016-10-11更新javascript

点击下载地址css

 

Video.js v5.8.8版 2016-4-11更新html

点击下载地址html5

 

Video.js历史v5.4.3版 2015-12-09更新java

点击下载地址jquery

 

Video.js 是一个通用的在网页上嵌入视频播放器的 JS 库,Video.js 自动检测浏览器对 HTML5 的支持状况,若是不支持 HTML5 则自动使用 Flash 播放器。web

使用方法

在页面中引用video-js.cs样式文件和video.jsajax

1
2
< link  href = "video-js.css"  rel = "stylesheet"  type = "text/css" >
< script  src = "video.js" ></ script >

 

设置flash路径,Video.js会在不支持html5的浏览中使用flash播放视频文件浏览器

1
2
3
<script>
     videojs.options.flash.swf =  "video-js.swf" ;
</script>

html服务器

poster="**"播放初始图。可以使用三种视频格式,根据所须要格式选择对应的。

1
2
3
4
5
6
7
8
9
< video  id = "example_video_1"  class = "video-js vjs-default-skin"  controls  preload = "none"  width = "640"  height = "264"
       data-setup = "{}" >
     < source  src = "http://视频地址格式1.mp4"  type = 'video/mp4'  />
     < source  src = "http://视频地址格式2.webm"  type = 'video/webm'  />
     < source  src = "http://视频地址格式3.ogv"  type = 'video/ogg'  />
     < track  kind = "captions"  src = "demo.captions.vtt"  srclang = "en"  label = "English" ></ track > <!-- Tracks need an ending tag thanks to IE9 -->
     < track  kind = "subtitles"  src = "demo.captions.vtt"  srclang = "en"  label = "English" ></ track > <!-- Tracks need an ending tag thanks to IE9 -->
</ video >

设置自动播放将下面代码加到html中代码后面

1
2
3
4
5
6
7
<script type= "text/javascript" >
     var  myPlayer = videojs( 'example_video_1' );
     videojs( "example_video_1" ).ready( function (){
         var  myPlayer =  this ;
         myPlayer.play();
     });
</script>

默认状况下,大的播放按钮是被定为在左上角的,这样就不会覆盖视频内容。若是你想让这个播放按钮居中,你能够给你的 video 标签添加额外的 vjs-big-play-centered 样式,好比:

1
2
3
4
5
6
<video id= "example_video_1"  class= "video-js vjs-default-skin vjs-big-play-centered"
   controls preload= "auto"  width= "640"  height= "264"
   data-setup= '{"example_option":true}' >
   ...
</video>

若是你还对播放按钮样式不满意可从新定义.video-js .vjs-big-play-button{/*这里的样式重写*/}。

为动态加载的 HTML 元素设置 Video.js

若是你的 web 页面或者应用是动态加载 video 标签的(ajax,appendChild,等等),这样在页面加载后这个元素是不存在的,那么你会想要手动设置播放器而不是依靠 data-setup 属性。要作到这一点,首先将 data-setup属性从 video 标签中移除掉,这样在播放器初始化的时候就不会混乱了。接下来,运行下面的 javascript ,有时在 Video.js 加载后,有时是在 video 标签被加载进 DOM 后,

1
2
3
videojs( "example_video_1" , {},  function (){
   // Player (this) is initialized and ready.
});

videojs 方法中的第一个参数是你的 video 标签的 ID,用你本身的代替。

第二个参数是一个选项对象。它容许你像设置 data-setup 属性同样设置额外的选项。

第三个参数是一个 'ready' 回调。一旦 Video.js 初始化完成后,就会触发这个回调。

你也能够传入一个元素自己的引用来代替元素ID:

1
2
3
4
5
6
7
videojs(document.getElementById( 'example_video_1' ), {},  function () {
   // This is functionally the same as the previous example.
});
videojs(document.getElementsByClassName( 'awesome_video_class' )[0], {},  function () {
   // You can grab an element by class if you'd like, just make sure
   // if it's an array that you pick one (here we chose the first).
});

若是您没法播放内容,您得确保使用了 正确的格式,你的 HTTP 服务器可能没法提供正确的 MIME类型 的内容

相关文章
相关标签/搜索