-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvjs.extern.js
28 lines (28 loc) · 11.7 KB
/
vjs.extern.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
vjs.Youtube=function(a,b,c){vjs.MediaTechController.call(this,a,b,c);if((a=b.source.src.match(/^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/))&&11==a[2].length)if(this.videoId=a[2],!this.player_.options_.ytcontrols){this.player_.poster("http://img.youtube.com/vi/"+this.videoId+"/0.jpg");var f=this;setTimeout(function(){f.player_.posterImage.el_.style.backgroundSize="cover"},50)}this.id_=this.player_.id()+"_youtube_api";a={enablejsapi:1,iv_load_policy:3,playerapiid:this.id(),disablekb:1,
controls:this.player_.options_.ytcontrols?1:0,showinfo:0,modestbranding:1,rel:0,origin:window.location.origin,autoplay:this.player_.options_.autoplay?1:0,loop:this.player_.options_.loop?1:0};this.el_.src="http://www.youtube.com/embed/"+this.videoId+"?"+vjs.Youtube.makeQueryString(a);this.player_.options_.ytcontrols&&(f=this,setTimeout(function(){f.player_.bigPlayButton.hide()},50));vjs.Youtube.apiReady?this.loadYoutube():(vjs.Youtube.loadingQueue.push(this),vjs.Youtube.apiLoading||(a=vjs.createEl("script",
{src:"http://www.youtube.com/iframe_api"}),b=document.getElementsByTagName("script")[0],b.parentNode.insertBefore(a,b),vjs.Youtube.apiLoading=!0))};goog.inherits(vjs.Youtube,vjs.MediaTechController);vjs.Youtube.prototype.dispose=function(){vjs.Youtube.superClass_.dispose.call(this);this.ytplayer.destroy()};
vjs.Youtube.prototype.createEl=function(){var a=this.player_,b=vjs.createEl("iframe",{id:a.id()+"_youtube_api",className:"vjs-tech",scrolling:"no",marginWidth:0,marginHeight:0,frameBorder:0,webkitAllowFullScreen:"",mozallowfullscreen:"",allowFullScreen:""});vjs.insertFirst(b,a.el());return b};vjs.Youtube.prototype.play=function(){this.player_.isReady_?this.ytplayer.playVideo():(this.playOnReady=!0,this.player_.options.ytcontrols||this.player_.bigPlayButton.show())};vjs.Youtube.prototype.pause=function(){this.ytplayer.pauseVideo()};
vjs.Youtube.prototype.paused=function(){return this.lastState!==YT.PlayerState.PLAYING&&this.lastState!==YT.PlayerState.BUFFERING};vjs.Youtube.prototype.currentTime=function(){return this.ytplayer.getCurrentTime()};vjs.Youtube.prototype.setCurrentTime=function(a){this.ytplayer.seekTo(a,!0);this.player_.trigger("timeupdate")};vjs.Youtube.prototype.duration=function(){return this.ytplayer.getDuration()};
vjs.Youtube.prototype.buffered=function(){var a=this.ytplayer.getVideoBytesLoaded(),b=this.ytplayer.getVideoBytesTotal();if(!a||!b)return 0;var c=this.ytplayer.getDuration(),a=a/b*c,b=this.ytplayer.getVideoStartBytes()/b*c;return vjs.createTimeRange(b,b+a)};vjs.Youtube.prototype.volume=function(){isNaN(this.volumeVal)&&(this.volumeVal=this.ytplayer.getVolume()/100);return this.volumeVal};
vjs.Youtube.prototype.setVolume=function(a){a&&a!=this.volumeVal&&(this.ytplayer.setVolume(100*a),this.volumeVal=a,this.player_.trigger("volumechange"))};vjs.Youtube.prototype.muted=function(){return this.ytplayer.isMuted()};vjs.Youtube.prototype.setMuted=function(a){a?this.ytplayer.mute():this.ytplayer.unMute();var b=this;setTimeout(function(){b.player_.trigger("volumechange")},50)};
vjs.Youtube.prototype.onReady=function(){this.player_.trigger("techready");this.player_.posterImage.hide();this.triggerReady();this.player_.trigger("durationchange");this.playOnReady&&(this.player_.bigPlayButton.hide(),this.ytplayer.playVideo());(!this.player_.options_.controls||this.player_.options_.ytcontrols)&&this.player_.controlBar.hide()};
vjs.Youtube.prototype.onStateChange=function(a){if(a!=this.lastState){switch(a){case -1:this.player_.trigger("durationchange");break;case YT.PlayerState.ENDED:this.player_.trigger("ended");this.player_.options_.ytcontrols||this.player_.bigPlayButton.show();break;case YT.PlayerState.PLAYING:this.player_.trigger("timeupdate");this.player_.trigger("durationchange");this.player_.trigger("playing");this.player_.trigger("play");break;case YT.PlayerState.PAUSED:this.player_.trigger("pause");break;case YT.PlayerState.BUFFERING:this.player_.trigger("timeupdate"),
this.player_.trigger("waiting"),this.player_.loadingSpinner.hide()}this.lastState=a}};
vjs.Youtube.prototype.onPlaybackQualityChange=function(a){switch(a){case "medium":this.player_.videoWidth=480;this.player_.videoHeight=360;break;case "large":this.player_.videoWidth=640;this.player_.videoHeight=480;break;case "hd720":this.player_.videoWidth=960;this.player_.videoHeight=720;break;case "hd1080":this.player_.videoWidth=1440;this.player_.videoHeight=1080;break;case "highres":this.player_.videoWidth=1920;this.player_.videoHeight=1080;break;case "small":this.player_.videoWidth=320;this.player_.videoHeight=
240;break;default:this.player_.videoWidth=0,this.player_.videoHeight=0}this.player_.trigger("ratechange")};vjs.Youtube.prototype.onError=function(a){this.player_.error=a;this.player_.trigger("error")};vjs.Youtube.isSupported=function(){return!0};vjs.Youtube.canPlaySource=function(a){return"video/youtube"==a.type};vjs.Youtube.prototype.features={fullscreen:!0,volumeControl:!0,progressEvents:!1,timeupdateEvents:!1};vjs.Youtube.loadingQueue=[];
vjs.Youtube.prototype.loadYoutube=function(){this.ytplayer=new YT.Player(this.id(),{events:{onReady:function(a){a.target.vjsTech.onReady()},onStateChange:function(a){a.target.vjsTech.onStateChange(a.data)},onPlaybackQualityChange:function(a){a.target.vjsTech.onPlaybackQualityChange(a.data)},onError:function(a){a.target.vjsTech.onError(a.data)}}});this.ytplayer.vjsTech=this};
vjs.Youtube.makeQueryString=function(a){var b=[],c;for(c in a)a.hasOwnProperty(c)&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")};window.onYouTubeIframeAPIReady=function(){for(var a;a=vjs.Youtube.loadingQueue.shift();)a.loadYoutube();vjs.Youtube.loadingQueue=[]};var VimeoState={UNSTARTED:-1,ENDED:0,PLAYING:1,PAUSED:2,BUFFERING:3};
vjs.Vimeo=function(a,b,c){vjs.MediaTechController.call(this,a,b,c);if(a=b.source.src.match(/^.*(vimeo\.com\/)((channels\/[A-z]+\/)|(groups\/[A-z]+\/videos\/))?([0-9]+)/))this.videoId=a[5];this.id_=this.player_.id()+"_vimeo_api";a={api:1,byline:0,portrait:0,show_title:0,show_byline:0,show_portait:0,fullscreen:1,player_id:this.id(),autoplay:this.player_.options_.autoplay?1:0,loop:this.player_.options_.loop?1:0};this.baseUrl="https"==document.location.protocol?"https://secure.vimeo.com/video/":"http://player.vimeo.com/video/";
this.vimeo={};this.vimeoInfo={};this.el_.vjsTech=this;this.el_.onload=function(){this.vjsTech.onLoad()};this.el_.src=this.baseUrl+this.videoId+"?"+vjs.Vimeo.makeQueryString(a)};goog.inherits(vjs.Vimeo,vjs.MediaTechController);vjs.Vimeo.prototype.dispose=function(){vjs.Vimeo.superClass_.dispose.call(this);this.vimeo.api("unload");delete this.vimeo;this.el_.parentNode.removeChild(this.el_)};
vjs.Vimeo.prototype.createEl=function(){var a=this.player_,b=vjs.createEl("iframe",{id:a.id()+"_vimeo_api",className:"vjs-tech",scrolling:"no",marginWidth:0,marginHeight:0,frameBorder:0,webkitAllowFullScreen:"",mozallowfullscreen:"",allowFullScreen:""});vjs.insertFirst(b,a.el());return b};
vjs.Vimeo.prototype.onLoad=function(){this.vimeo=$f(this.el_);this.vimeoInfo={state:VimeoState.UNSTARTED,volume:1,muted:!1,muteVolume:1,time:0,duration:0,buffered:0,url:this.baseUrl+this.videoId,error:null};this.vimeo.addEvent("ready",function(a){vjs.el(a).vjsTech.onReady()});this.vimeo.addEvent("loadProgress",function(a,b){vjs.el(b).vjsTech.onLoadProgress(a)});this.vimeo.addEvent("playProgress",function(a,b){vjs.el(b).vjsTech.onPlayProgress(a)});this.vimeo.addEvent("play",function(a){vjs.el(a).vjsTech.onPlay()});
this.vimeo.addEvent("pause",function(a){vjs.el(a).vjsTech.onPause()});this.vimeo.addEvent("finish",function(a){vjs.el(a).vjsTech.onFinish()});this.vimeo.addEvent("seek",function(a){vjs.el(a).vjsTech.onSeek(data)})};vjs.Vimeo.prototype.play=function(){this.vimeo.api("play")};vjs.Vimeo.prototype.pause=function(){this.vimeo.api("pause")};vjs.Vimeo.prototype.paused=function(){return this.lastState!==VimeoState.PLAYING&&this.lastState!==VimeoState.BUFFERING};
vjs.Vimeo.prototype.currentTime=function(){return this.vimeoInfo.time||0};vjs.Vimeo.prototype.setCurrentTime=function(a){this.vimeo.api("seekTo",a);this.player_.trigger("timeupdate")};vjs.Vimeo.prototype.duration=function(){return this.vimeoInfo.duration||0};vjs.Vimeo.prototype.buffered=function(){return vjs.createTimeRange(0,this.vimeoInfo.buffered||0)};vjs.Vimeo.prototype.volume=function(){return this.vimeoInfo.muted?this.vimeoInfo.muteVolume:this.vimeoInfo.volume};
vjs.Vimeo.prototype.setVolume=function(a){this.vimeo.api("setvolume",a);this.vimeo.vimeoInfo.volume=a;this.player_.trigger("volumechange")};vjs.Vimeo.prototype.muted=function(){return this.vimeoInfo.muted||!1};vjs.Vimeo.prototype.setMuted=function(a){a?(this.vimeoInfo.muteVolume=this.vimeoInfo.volume,this.setVolume(0)):this.setVolume(this.vimeoInfo.muteVolume);this.vimeoInfo.muted=a;this.player_.trigger("volumechange")};
vjs.Vimeo.prototype.onReady=function(){this.triggerReady();this.player_.trigger("canplay");this.player_.bigPlayButton.hide();this.player_.posterImage.hide();this.player_.controlBar.hide()};vjs.Vimeo.prototype.onLoadProgress=function(a){var b=!this.vimeoInfo.duration;this.vimeoInfo.duration=a.duration;this.vimeoInfo.buffered=a.percent;this.player_.trigger("progress");b&&this.player_.trigger("durationchange")};vjs.Vimeo.prototype.onPlayProgress=function(a){this.vimeoInfo.time=a.seconds;this.player_.trigger("timeupdate")};
vjs.Vimeo.prototype.onPlay=function(){this.vimeoInfo.state=VimeoState.PLAYING;this.player_.trigger("play")};vjs.Vimeo.prototype.onPause=function(){this.vimeoInfo.state=VimeoState.PAUSED;this.player_.trigger("pause")};vjs.Vimeo.prototype.onFinish=function(){this.vimeoInfo.state=VimeoState.ENDED;this.player_.trigger("ended")};vjs.Vimeo.prototype.onSeek=function(a){this.vimeoInfo.time=a.seconds;this.player_.trigger("timeupdate");this.player_.trigger("seeked")};vjs.Vimeo.isSupported=function(){return!0};
vjs.Vimeo.canPlaySource=function(a){return"video/vimeo"==a.type};vjs.Vimeo.prototype.features={fullscreen:!0,volumeControl:!0};vjs.Vimeo.makeQueryString=function(a){var b=[],c;for(c in a)a.hasOwnProperty(c)&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")};
var Froogaloop=function(){function a(k){return new a.fn.init(k)}function b(a,b,d){if(!d.contentWindow.postMessage)return!1;var c=d.getAttribute("src").split("?")[0];a=JSON.stringify({method:a,value:b});"//"===c.substr(0,2)&&(c=window.location.protocol+c);d.contentWindow.postMessage(a,c)}function c(a){var b,d;try{b=JSON.parse(a.data),d=b.event||b.method}catch(c){}"ready"==d&&!h&&(h=!0);if(a.origin!=j)return!1;a=b.value;var f=b.data,g=""===g?null:b.player_id;b=g?e[g][d]:e[d];d=[];if(!b)return!1;void 0!==
a&&d.push(a);f&&d.push(f);g&&d.push(g);return 0<d.length?b.apply(null,d):b.call()}function f(a,b,d){d?(e[d]||(e[d]={}),e[d][a]=b):e[a]=b}var e={},h=!1,j="";a.fn=a.prototype={element:null,init:function(a){"string"===typeof a&&(a=document.getElementById(a));this.element=a;a=this.element.getAttribute("src");"//"===a.substr(0,2)&&(a=window.location.protocol+a);a=a.split("/");for(var b="",d=0,c=a.length;d<c;d++){if(3>d)b+=a[d];else break;2>d&&(b+="/")}j=b;return this},api:function(a,c){if(!this.element||
!a)return!1;var d=this.element,e=""!==d.id?d.id:null,h=!c||!c.constructor||!c.call||!c.apply?c:null,g=c&&c.constructor&&c.call&&c.apply?c:null;g&&f(a,g,e);b(a,h,d);return this},addEvent:function(a,c){if(!this.element)return!1;var d=this.element,e=""!==d.id?d.id:null;f(a,c,e);"ready"!=a?b("addEventListener",a,d):"ready"==a&&h&&c.call(null,e);return this},removeEvent:function(a){if(!this.element)return!1;var c=this.element,d=""!==c.id?c.id:null;a:{if(d&&e[d]){if(!e[d][a]){d=!1;break a}e[d][a]=null}else{if(!e[a]){d=
!1;break a}e[a]=null}d=!0}"ready"!=a&&d&&b("removeEventListener",a,c)}};a.fn.init.prototype=a.fn;window.addEventListener?window.addEventListener("message",c,!1):window.attachEvent("onmessage",c);return window.Froogaloop=window.$f=a}();