filesbox/web/dist/design/index/component/player/index.js
2024-07-26 14:10:54 +08:00

2 lines
11 KiB
JavaScript

(function(o,u){if(u.player||!u.loadScriptmin)return!1;u.player={init:function(){var e=this;e.checkVideo(),(o(".player").length>0||window.backvedio!=0&&o(".content").length>0)&&loadScriptmin.apply(e,[(window.cdnPath||"")+"/design/designstatic/home/js/video/video.min.js",function(){loadScriptmin.apply(e,[(window.cdnPath||"")+"/design/designstatic/home/js/video/videojs-contrib-hls.min.js",e.hasVideo])}])},hasVideo:function(){var e=this;if(window.backvedio&&window.backvedio!=0&&o(".content").length>0){e.getBgVedioUrl(),o(".content").css({position:"relative","z-index":"1"});var a={backgroundImage:"url("+bgVideoPic+")",backgroundSize:"100% "+o(window).height()+"px",backgroundRepeat:"no-repeat",backgroundAttachment:"fixed"};o("body").css(a)}e.getVideoDatas(),e.bindPlayerLayer()},checkVideo:function(){var e=this;if(!!document.createElement("video").canPlayType&&e.IEVersion(!0)){var a=document.createElement("video");return oggTest=a.canPlayType('video/ogg; codecs="theora, vorbis"'),oggTest?oggTest=="probably":(h264Test=a.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"'),h264Test?h264Test=="probably":!1)}else return!1},IEVersion:function(e){var a=navigator.userAgent,n=a.indexOf("compatible")>-1&&a.indexOf("MSIE")>-1,t=a.indexOf("Edge")>-1&&!n,r=a.indexOf("Trident")>-1&&a.indexOf("rv:11.0")>-1;return n?!1:t||r?!0:e},getBgVedioUrl:function(){var e=this;o.ajax({type:"get",url:"/room/design/getvediourl.html",data:{cwid:backvedio,did:did||0},dataType:"json",success:function(a){a.code<1&&e.carryBgVideo(a.data)}})},carryBgVideo:function(e){var a=this;if(a.IEVersion(!1))a.carryObjectDrawImage(e);else{var n='<video id="backvedio" class="video-js vjs-default-skin" style="display:none;" loop muted playsinline webkit-playsinline controls preload="auto" x-webkit-airplay="true" controlsList="nodownload" oncontextmenu="return false" ><source src="'+(window.cdnPath||"")+e+'" type="application/x-mpegURL"></video>';o("body").append(n),window.videojs("backvedio",{},function(){this.play()}),a.carryCanvasDrawImage()}},carryObjectDrawImage:function(e){var a=o(window).width(),n=o(window).height(),t='<video id="backvedio" class="video-js vjs-default-skin" width="'+a+'" playsinline loop muted webkit-playsinline controls="false" preload="auto" x-webkit-airplay="true" controlsList="nodownload" oncontextmenu="return false" ><source src="'+(window.cdnPath||"")+e+'" type="application/x-mpegURL"></video>';o("body").append(t),o("#backvedio").css({position:"fixed",top:"0",left:"0"}),window.onresize=function(){a=o(window).width(),n=o(window).height()},window.videojs("backvedio",{},function(){this.play(),o("#backvedio .vjs-control-bar").hide()})},carryCanvasDrawImage:function(){var e=document.createElement("canvas");e.id="myCanvas",document.body.appendChild(e);var a=document.getElementById("backvedio_html5_api"),n=document.getElementById("myCanvas"),t=o(window).width(),r=o(window).height();o("#myCanvas").css({position:"fixed",top:"0",left:"0"}),window.onresize=function(){t=o(window).width(),r=o(window).height()},n.width=t,n.height=r;var d=n.getContext("2d");a.addEventListener("play",function(){var s=window.setInterval(function(){d.drawImage(a,0,0,t,r)},20)},!1),a.addEventListener("pause",function(){window.clearInterval(i)},!1),a.addEventListener("ended",function(){clearInterval(i)},!1)},getVideoDatas:function(){var e=this;e.playParams={},e.IEVersion(!1)&&o("head").append("<style>.video-js .vjs-tech, .video-js.vjs-fill{width:auto; max-width:100%;}</style>"),e.playElement=o(".module[data-type=player]"),e.playerdatas=[];for(var a=0,n=e.playElement.length;a<n;a++){var t=e.playElement.eq(a),r=o.parseJSON(t.attr("data-player"));e.getCreateVideoConfig(t,r)}},getCreateVideoConfig:function(e,a){var n=this,n=this,t="player"+e.attr("data-mid");e.find(".box").append('<div id="'+t+'"></div>');var r=parseInt(e.css("width")),d=parseInt(e.css("height"));n.playParams[t]={dom:e,playerId:t,playMenus:a.list,designId:a.designId,autoPlay:a.play,loop:a.loop||!1,controls:a.controls,playIndex:0,width:r,height:d},n.getVedioUrl(t),e.find("li").on("click",function(){n.playParams[t].playIndex=o(this).index(),n.getVedioUrl(t)})},getVedioUrl:function(e){var a=this,n=a.playParams[e],t=n.playIndex,r=n.playMenus[t].videoid,d=n.playMenus[t].sourceId,s=o("#"+n.playerId).parent().find(".rightMenu");s.find(".on").removeClass("on"),s.find("li").eq(n.playIndex).addClass("on"),s.parent().css("backgroundImage","url("+a.coverCDNUrl(n.playMenus[t].src)+")"),o.ajax({type:"get",url:"/api/course/getCourseWareInfoByIds?projectid=12",data:{courseWareIds:r,isIndex:1},contentType:"application/json",dataType:"json",success:function(c){c.success&&a.carryVideo(n,c.data[0],d)}})},coverCDNUrl:function(e){return e.indexOf("http")<0||e.indexOf("//")<0?(window.cdnPath||"")+e:e},carryVideo:function(e,a,n){var t=this,r=e.dom,d=e.playerId,t=this,s="";if(e.designId)s="/api/common/mu/getDesignFreeM3u8.m3u8?courseWareId="+a.courseWareId+"&designId="+e.designId+(n?"&sourceId="+n:"");else if(s=(window.cdnPath||"")+a.videoM3u8FileAddress,!s)return layer.msg("\u5F53\u524D\u89C6\u9891\u4E0D\u5B58\u5728",{icon:5}),!1;var c=r.find(".vjs-tech");if(c.length<1){var l="moduleVideoID"+d,y=e.controls?"":"<style>#"+l+" .vjs-control-bar{display: none;}</style>",v='<style id="style'+l+'"></style>'+y+'<video data-class="coverVideo" id="'+l+'" class="video-js vjs-default-skin" poster="'+t.coverCDNUrl(e.playMenus[e.playIndex].src)+'" controls width="'+e.width+'" height="'+e.height+'" style="background-color:#333;" playsinline webkit-playsinline preload="auto" ></video>';o("#"+e.playerId).html(v);var p=document.getElementById(l);t.getVideoStyle(e,l),e.loop&&e.playMenus.length==1&&(p.loop=!0),e.autoPlay&&(p.muted=!0,p.play()),e.controls||o("video").on("click",function(){p.muted&&(p.muted=!1,p.play())}),p.addEventListener("ended",function(){e.playMenus.length-1>e.playIndex?(e.playIndex++,t.getVedioUrl(d)):e.loop&&(e.playIndex=0,t.getVedioUrl(d))},!1),t.IEVersion(!0)||(videojs.options.flash.swf="/design/designstatic/js/video/VideoJS.swf"),window[d]=window.videojs(l,{techOrder:t.IEVersion(!0)?["html5"]:["flash"]},function(){if(window[d].src({src:s,type:"application/x-mpegURL"}),e.autoPlay){var g=this;setTimeout(function(){g.play()},0)}})}else window[d].src({src:s,type:"application/x-mpegURL"}),window[d].play(),t.getVideoStyle(e,"moduleVideoID"+d)},getVideoStyle:function(e,a){var n=16/9,t=e.playIndex,r=e.playMenus[t].videoid;o.ajax({type:"get",url:"/api/common/tool/videoWidthHeight",data:{busId:r,busType:"doc"},contentType:"application/json",dataType:"json",success:function(d){if(d.success){var s="#"+a+"_html5_api",c=o(s).length?o("#"+a+"_html5_api"):o("#"+a),l=o("#style"+a),y=d.data.split("*"),v=y[0],p=y[1],f=v/p?v/p:16/9;if(f>n){var g=(n/f*100).toFixed(0);l.html(".video-js.vjs-fullscreen "+s+"{height:"+g+"%}")}else{var h=(f/n*100).toFixed(0);l.html(".video-js.vjs-fullscreen "+s+"{width:"+h+"%}")}}}})},bindPlayerLayer:function(){var e=this;o(".module[data-handle=audition]").on("click",function(){e.playerLayer(o(this))})},getUrlParms:function(e){var a=this,n=new RegExp("(^|&)"+e+"=([^&]*)(&|$)"),t=a.videoItem.attr("data-handleaudition").match(n);return t!=null?unescape(t[2]):null},playerLayer:function(e){var a=this;a.videoItem=e;var n="/api/common/mu/getDesignFreeM3u8.m3u8?courseWareId="+a.getUrlParms("courseWareId")+"&designId="+a.getUrlParms("designId")+(a.getUrlParms("sourceId")?"&sourceId="+a.getUrlParms("sourceId"):""),t=layer.open({type:1,title:"\u89C6\u9891",shade:.6,skin:"layui-layer-antd",area:["900px","611px"],cancel:function(r){window.playerVideoId.dispose(),layer.close(t)},success:function(r,d){window.playerVideoId=window.videojs("playerVideoId",{techOrder:a.IEVersion(!0)?["html5"]:["flash"]},function(){window.playerVideoId.src({src:n,type:"application/x-mpegURL"});var c=this;setTimeout(function(){c.play()},0)})},content:'<div class="video_main"> <video id="playerVideoId" class="video-js vjs-default-skin" controls width="900" height="562" style="background-color:#333;" playsinline webkit-playsinline preload="auto" ></video> </div>'})},getPlayerDatas:function(){var e=this;e.playElement=o(".module[data-type=player]"),e.playerdatas=[];for(var a=0,n=e.playElement.length;a<n;a++){var t=e.playElement.eq(a),r=o.parseJSON(t.attr("data-player"));e.getCreatePlayerConfig(t,r)}},getCreatePlayerConfig:function(e,a){var n=this,t="player0228";e.find(".box").append('<div id="'+t+'"></div>');var r=parseInt(e.css("width")),d=parseInt(e.css("height"));n.playParams={playerId:t,playMenus:a.list,autoPlay:a.play,playIndex:0,width:r,height:d},n.getAjaxPlayerUrl(),e.find("li").on("click",function(){n.playParams.playIndex=o(this).index(),n.getAjaxPlayerUrl()})},getAjaxPlayerUrl:function(){var e=this,a=e.playParams,n=a.playIndex,t=a.playMenus[n].videoid,r=a.playMenus[n].sourceId,d=o("#"+a.playerId).parent().find(".rightMenu");d.find(".on").removeClass("on"),d.find("li").eq(a.playIndex).addClass("on"),d.parent().css("backgroundImage","url("+a.playMenus[n].src+")"),o.ajax({type:"get",url:"/api/course/getCourseWareInfoByIds?projectid=12",data:{courseWareIds:t,isIndex:1},contentType:"application/json",dataType:"json",success:function(s){if(s.success){var c=s.data[0],l="";if(a.designId)l="/api/common/mu/getDesignFreeM3u8.m3u8?courseWareId="+c.courseWareId+"&designId="+a.designId+(r?"&sourceId="+r:"");else if(l=(window.cdnPath||"")+c.videoM3u8FileAddress,!l)return layer.msg("\u5F53\u524D\u89C6\u9891\u4E0D\u5B58\u5728",{icon:5}),!1;l="/api/common/mu/getDesignFreeM3u8.m3u8?courseWareId=630224&designId=240080",e.carryPlayer(a,u.escape(l))}}})},carryPlayer:function(e,a){var n=this;swfobject.embedSWF("/design/designstatic/home/js/video/playerv3.swf",e.playerId,e.width||1e3,e.height||600,"10.0.0","/design/designstatic/home/js/video/expressInstall.swf",{looktime:0,source:a,type:"video",streamtype:"file",server:"",duration:"52",poster:"",autostart:"false",logo:"",logoposition:"top left",logoalpha:30,logowidth:"130",logolink:"/",hardwarescaling:!1,darkcolor:"000000",brightcolor:"4c4c4c",controlcolor:"FFFFFF",hovercolor:"67A8C1",controltype:1,picurl:e.playMenus[e.playIndex].thumb,size:e.playMenus[e.playIndex].size,classover:e.autoPlay&&e.playMenus&&e.playMenus.length>1?1:0,pageControl:e.autoPlay?1:0,seek:-1,mode:0,isremind:0},{menu:"false",scale:"noScale",allowFullscreen:"true",allowScriptAccess:"always",bgcolor:"#000000",quality:"high",wmode:"Opaque"},{id:e.playerId},swfloadcall)}},window.self==window.top&&u.player.init()})(jQuery,window);function messfun(o,u,e,a,n){player.checkVideo()||(player.playParams.playIndex++,player.playParams.autoPlay&&player.playParams.playMenus.length>1&&player.playParams.playIndex<player.playParams.playMenus.length&&player.getAjaxPlayerUrl())}function swfloadcall(o){typeof o!="undefined"&&typeof o.success!="undefined"&&o.success==!1&&$("#"+player.playParams.playerId).html('<span style="margin-left:200px;font-size:18px;line-height:300px;color:#000">\u60A8\u8FD8\u6CA1\u6709\u5B89\u88C5flash\u64AD\u653E\u5668,\u8BF7\u70B9\u51FB<a href="//www.adobe.com/go/getflash" target="_blank" style="color:red;font-weight:bold;">\u8FD9\u91CC</a>\u5B89\u88C5</span>')}