HTML5 - 两款基于JS的视频播放器的使用说明(VideoJS和jPlayer)
通常我们使用HTML5播放器播放视频时,还要考虑浏览器兼容。像IE8这种不支持<video>的古董级浏览器,就需要提供Flash播放器作为备用方案。这些如果都要自己弄就很麻烦。
代码下载:jPlayer.zip
这两个体积都很小,支持换肤,使用方便。同时都支持Flash作为后备播放器。
1,VideoJS的使用
VideoJS的使用方法和普通的<video>标签一样,只需把相关的js和css引入配置即可。同时可以设置使用哪种备用的Flash播放器(比如flowplayer)
支持HTML5播放的浏览器效果如下:
不支持HTML5的自动使用Flash播放器(比如IE8):
(注意:IE8的话要将页面放到服务器器上测试)
代码如下:
<!DOCTYPE html> <html> <head> <title>Video.js | hangge.com</title> <!-- 播放器样式 --> <link href="video-js.css" rel="stylesheet" type="text/css"> <!-- 如果要支持IE8 --> <script src="ie8/videojs-ie8.js"></script> <!-- 播放器js --> <script src="video.js"></script> </head> <body> <video id="example_video_1" class="video-js vjs-default-skin" controls preload="none" width="400" height="300" poster="hangge-clip.png" data-setup="{}"> <source src="hangge.mp4" type='video/mp4' /> <source src="hangge.webm" type='video/webm' /> <source src="hangge.ogv" type='video/ogg' /> <track kind="captions" src="hangge.vtt" srclang="en" label="English" /> </video> </body> </html>
样例下载:
video-js.zip(老版本)
2,jPlayer的使用
jPlayer看名字的话就知道需要调用jQuery。
而且jPlayer提供了自己的播放列表功能,让用户可以把音频和视频文件组织到一个列表中。
不管在那种浏览器下,使用HTML5还是Flash播放器,样式都是一样的:
代码如下:
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>jPlayer as a video player | hangge.com</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link href="./dist/skin/blue.monday/css/jplayer.blue.monday.min.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="./lib/jquery.min.js"></script> <script type="text/javascript" src="./dist/jplayer/jquery.jplayer.min.js"></script> <script type="text/javascript"> //<![CDATA[ $(document).ready(function(){ $("#jquery_jplayer_1").jPlayer({ ready: function () { $(this).jPlayer("setMedia", { title: "Big Buck Bunny", m4v: "http://www.jplayer.org/video/m4v/Big_Buck_Bunny_Trailer.m4v", ogv: "http://www.jplayer.org/video/ogv/Big_Buck_Bunny_Trailer.ogv", webmv: "http://www.jplayer.org/video/webm/Big_Buck_Bunny_Trailer.webm", poster: "http://www.jplayer.org/video/poster/Big_Buck_Bunny_Trailer_480x270.png" }); }, swfPath: "./dist/jplayer", supplied: "webmv, ogv, m4v", size: { width: "480px", height: "300px", cssClass: "jp-video-270p" }, useStateClassSkin: true, autoBlur: false, smoothPlayBar: true, keyEnabled: true, remainingDuration: true, toggleDuration: true }); }); //]]> </script> </head> <body> <div id="jp_container_1" class="jp-video jp-video-270p" role="application" aria-label="media player"> <div class="jp-type-single"> <div id="jquery_jplayer_1" class="jp-jplayer"></div> <div class="jp-gui"> <div class="jp-video-play"> <button class="jp-video-play-icon" role="button" tabindex="0">play</button> </div> <div class="jp-interface"> <div class="jp-progress"> <div class="jp-seek-bar"> <div class="jp-play-bar"></div> </div> </div> <div class="jp-current-time" role="timer" aria-label="time"> </div> <div class="jp-duration" role="timer" aria-label="duration"> </div> <div class="jp-controls-holder"> <div class="jp-controls"> <button class="jp-play" role="button" tabindex="0">play</button> <button class="jp-stop" role="button" tabindex="0">stop</button> </div> <div class="jp-volume-controls"> <button class="jp-mute" role="button" tabindex="0">mute</button> <button class="jp-volume-max" role="button" tabindex="0">max volume</button> <div class="jp-volume-bar"> <div class="jp-volume-bar-value"></div> </div> </div> <div class="jp-toggles"> <button class="jp-repeat" role="button" tabindex="0">repeat</button> <button class="jp-full-screen" role="button" tabindex="0">full screen</button> </div> </div> <div class="jp-details"> <div class="jp-title" aria-label="title"> </div> </div> </div> </div> <div class="jp-no-solution"> <span>无法播放</span> 你需要安装flashplayer, 地址:<a href="http://get.adobe.com/flashplayer/" target="_blank">Flash plugin</a>. </div> </div> </div> </body> </html>
代码下载:jPlayer.zip
不需要引入播放插件吗
使用了5.8.7版本,也将版本放到了服务器上,但是IE8下还是不能显示了,是否需要将压缩包中的内容做调整? 我看html中没有再设置options.flash.swf,但是我增加了设置以后,IE8下还是不能播放。有什么可能原因么?
谢谢
您好,想问下这个videojs的版本和git上的相比有啥变化吗? 我比对代码看差别挺大。不知道您这边是否有做过什么修改?还是说这个版本是git上相对老的一个版本?
video-js.zip 解压在ie8 上执行过吗? 为什么我还是不能播放?