Posted in Javascript onDecember 21, 2016
三分屏,这里的三分屏只是在一个播放器里同时播放三个视频,但是要求只有一个控制面板同时控制它们,要求它们共享一个时间轨道。这次只是简单的模拟了一下功能,并没有深入的研究。
首先,需要下载jPlayer,jPlayer是一个JavaScript写的完全免费和开源的jQuery多媒体库插件,我觉得他最大的好处就是兼容性,并且页面也简洁大方,个人比较喜欢。jPlayer可到其官网下载最新版本(http://www.jplayer.cn)。并且官网有开发文档和Demo,所以还是比较容易上手的。
关于简单的视频播放器和音频播放器这里不再赘述了,官网的Demo挺好的,这里直奔主题。
首先当然是引入jPlayer相关文件。
首先是css文件夹,这里为了方便,某些文件也放到css文件夹里了:
然后是js文件夹:
因为jPlayer是在jQuery的插件,所以jquery的包自然也就少不了了。
新建一个test.jsp页面,下面是代码:
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>JPlayer Test</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <!-- 引入相关文件 --> <link href="css/jplayer.blue.monday.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="js/jquery.min.js"></script> <script type="text/javascript" src="css/jquery.jplayer.min.js"></script> <script type="text/javascript" src="js/jplayer.playlist.min.js"></script> <script type="text/javascript" src="test.js"></script> </head> <body> <div class="wrapper"> <div class="left-wrapper" style="float: left; width: 320px"> <div id="jp_container_2" class="jp-video jp-video-360p"> <div class="jp-type-single"> <!-- 左上的屏幕 --> <div ondblclick="fullScreen()" id="jquery_jplayer_2" class="jp-jplayer"></div> <!-- 左下的屏幕 --> <div ondblclick="fullScreen()" id="jquery_jplayer_3" class="jp-jplayer"></div> </div> </div> </div> <div class="right-wrapper" style="float: left;"> <div id="jp_container_1" class="jp-video jp-video-360p" style="border-bottom: none; border-left: none;"> <div class="jp-type-single"> <div ondblclick="fullScreen()" id="jquery_jplayer_1" class="jp-jplayer"></div> <div class="jp-gui" align="left"> <div class="jp-video-play" style="margin-left: -160px"> <button class="jp-video-play-icon">play</button> </div> <!-- 控制面板 --> <!-- width: 959px; margin-left: -320px; --> <div id="controller" class="jp-interface" style="border: 1px solid #009be3;"> <div class="jp-progress"> <div class="jp-seek-bar"> <div class="jp-play-bar"></div> </div> </div> <div class="jp-current-time"> </div> <div class="jp-duration"> </div> <div class="jp-controls-holder"> <div class="jp-controls"> <button class="jp-play">play</button> <button class="jp-stop">stop</button> </div> <div class="jp-volume-controls"> <button class="jp-mute">mute</button> <button class="jp-volume-max">max volume</button> <div class="jp-volume-bar"> <div class="jp-volume-bar-value"></div> </div> </div> <div class="jp-toggles"> <button class="jp-full-screen">full screen</button> </div> </div> <div class="jp-details"> <div class="jp-title" aria-label="title"> </div> </div> </div> </div> </div> </div> </div> </div> </body> </html>
新建一个test.js文件,下面是代码:
var flag = false; var isFull = false; $(document).ready(function() { // 实例化第一个视频 $("#jquery_jplayer_1").jPlayer({ ready: function() { $(this).jPlayer("setMedia", { title: "This is video Title", m4v: "http://www.jplayer.org/video/m4v/Big_Buck_Bunny_Trailer.m4v", /* m4v: "video/003.webm", */ poster: "http://www.jplayer.org/video/poster/Big_Buck_Bunny_Trailer_480x270.png" }); }, swfPath: "../../dist/jplayer", supplied: "m4v", size: { width: "640px", height: "360px", cssClass: "jp-video-360p" }, useStateClassSkin: true, autoBlur: false, smoothPlayBar: true, keyEnabled: true, remainingDuration: true, toggleDuration: true }); // 实例化第二个视频 $("#jquery_jplayer_2").jPlayer({ ready: function() { $(this).jPlayer("setMedia", { title: "This is video Title", m4v: "http://www.jplayer.org/video/m4v/Big_Buck_Bunny_Trailer.m4v", /* m4v: "video/003.webm", */ poster: "http://www.jplayer.org/video/poster/Big_Buck_Bunny_Trailer_480x270.png" }); }, swfPath: "../../dist/jplayer", supplied: "m4v", size: { width: "320px", height: "180px", cssClass: "jp-video-360p" }, useStateClassSkin: true, autoBlur: false, smoothPlayBar: true, keyEnabled: true, remainingDuration: true, toggleDuration: true }); // 实例化第三个视频 $("#jquery_jplayer_3").jPlayer({ ready: function() { $(this).jPlayer("setMedia", { title: "This is video Title", m4v: "http://www.jplayer.org/video/m4v/Big_Buck_Bunny_Trailer.m4v", /* m4v: "video/003.webm", */ poster: "http://www.jplayer.org/video/poster/Big_Buck_Bunny_Trailer_480x270.png" }); }, swfPath: "../../dist/jplayer", supplied: "m4v", size: { width: "320px", height: "180px", cssClass: "jp-video-360p" }, useStateClassSkin: true, autoBlur: false, smoothPlayBar: true, keyEnabled: true, remainingDuration: true, toggleDuration: true }); // 绑定初始化事件,用于在页面加载的时候初始化控制条的位置 $("#jquery_jplayer_1").bind($.jPlayer.event.ready, function(event) { $("#controller").css({ width: "959px", margin: "0px 0px 0px -320px" }); }); // 绑定页面大小变更事件,用于页面大小变化的时候,设置控制条的位置 $("#jquery_jplayer_1").bind($.jPlayer.event.resize, function(event) { if (!isFull) { $("#controller").css({ width: "100%", margin: "0" }); isFull = true; } else { $("#controller").css({ width: "959px", margin: "0px 0px 0px -320px" }); isFull = false; } }); // 绑定单击事件,用于单击屏幕控制视频的播放与暂停 $('#jquery_jplayer_1, #jquery_jplayer_2, #jquery_jplayer_3').bind("click", function(){ var $jplayer1 = $('#jquery_jplayer_1'); var $jplayer2 = $('#jquery_jplayer_2'); var $jplayer3 = $('#jquery_jplayer_3'); var status = $jplayer1.data("jPlayer").status; if (status.paused) { $jplayer1.jPlayer("play"); $jplayer2.jPlayer("play"); $jplayer3.jPlayer("play"); } else { $jplayer1.jPlayer("pause"); $jplayer2.jPlayer("pause"); $jplayer3.jPlayer("pause"); } }); }); // 双击屏幕时,进入全屏状态 function fullScreen() { $("#jquery_jplayer_1").jPlayer("option", "fullScreen", true); }
以上就是全部信息,需要注意的是,进入全屏状态的时候,只有主屏幕进入全屏,其它两个小的屏幕并不会进入全屏状态。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。
基于jPlayer三分屏的制作方法
- Author -
我叫乾乾声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@