You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1 lines
11 KiB

!function(a,b){"object"==typeof exports&&"undefined"!=typeof module?module.exports=b(require("video.js")):"function"==typeof define&&define.amd?define(["media_videojs/video-lazy"],function(c){return a.Youtube=b(c)}):a.Youtube=b(a.videojs)}(this,function(a){"use strict";function b(){YT.ready(function(){g.isApiReady=!0;for(var a=0;a<g.apiReadyQueue.length;++a)g.apiReadyQueue[a].initYTPlayer()})}function c(a,b){var c=!1,d=document.createElement("script"),e=document.getElementsByTagName("script")[0];e.parentNode.insertBefore(d,e),d.onload=function(){c||(c=!0,b())},d.onreadystatechange=function(){c||"complete"!==this.readyState&&"loaded"!==this.readyState||(c=!0,b())},d.src=a}function d(){var a=".vjs-youtube .vjs-iframe-blocker { display: none; }.vjs-youtube.vjs-user-inactive .vjs-iframe-blocker { display: block; }.vjs-youtube .vjs-poster { background-size: cover; }.vjs-youtube-mobile .vjs-big-play-button { display: none; }",b=document.head||document.getElementsByTagName("head")[0],c=document.createElement("style");c.type="text/css",c.styleSheet?c.styleSheet.cssText=a:c.appendChild(document.createTextNode(a)),b.appendChild(c)}var e=a.browser.IS_IOS||a.browser.IS_ANDROID,f=a.getTech("Tech"),g=a.extend(f,{constructor:function(a,b){f.call(this,a,b),this.setPoster(a.poster),this.setSrc(this.options_.source,!0),this.setTimeout(function(){this.el_&&(this.el_.parentNode.className+=" vjs-youtube",e&&(this.el_.parentNode.className+=" vjs-youtube-mobile"),g.isApiReady?this.initYTPlayer():g.apiReadyQueue.push(this))}.bind(this))},dispose:function(){if(this.ytPlayer)this.ytPlayer.stopVideo&&this.ytPlayer.stopVideo(),this.ytPlayer.destroy&&this.ytPlayer.destroy();else{var a=g.apiReadyQueue.indexOf(this);a!==-1&&g.apiReadyQueue.splice(a,1)}this.ytPlayer=null,this.el_.parentNode.className=this.el_.parentNode.className.replace(" vjs-youtube","").replace(" vjs-youtube-mobile",""),this.el_.parentNode.removeChild(this.el_),f.prototype.dispose.call(this)},createEl:function(){var a=document.createElement("div");a.setAttribute("id",this.options_.techId),a.setAttribute("style","width:100%;height:100%;top:0;left:0;position:absolute"),a.setAttribute("class","vjs-tech");var b=document.createElement("div");if(b.appendChild(a),!e&&!this.options_.ytControls){var c=document.createElement("div");c.setAttribute("class","vjs-iframe-blocker"),c.setAttribute("style","position:absolute;top:0;left:0;width:100%;height:100%"),c.onclick=function(){this.pause()}.bind(this),b.appendChild(c)}return b},initYTPlayer:function(){var a={controls:0,modestbranding:1,rel:0,showinfo:0,loop:this.options_.loop?1:0};if("undefined"!=typeof this.options_.autohide&&(a.autohide=this.options_.autohide),"undefined"!=typeof this.options_.cc_load_policy&&(a.cc_load_policy=this.options_.cc_load_policy),"undefined"!=typeof this.options_.ytControls&&(a.controls=this.options_.ytControls),"undefined"!=typeof this.options_.disablekb&&(a.disablekb=this.options_.disablekb),"undefined"!=typeof this.options_.end&&(a.end=this.options_.end),"undefined"!=typeof this.options_.color&&(a.color=this.options_.color),a.controls?"undefined"!=typeof this.options_.fs&&(a.fs=this.options_.fs):a.fs=0,"undefined"!=typeof this.options_.end&&(a.end=this.options_.end),"undefined"!=typeof this.options_.hl?a.hl=this.options_.hl:"undefined"!=typeof this.options_.language&&(a.hl=this.options_.language.substr(0,2)),"undefined"!=typeof this.options_.iv_load_policy&&(a.iv_load_policy=this.options_.iv_load_policy),"undefined"!=typeof this.options_.list?a.list=this.options_.list:this.url&&"undefined"!=typeof this.url.listId&&(a.list=this.url.listId),"undefined"!=typeof this.options_.listType&&(a.listType=this.options_.listType),"undefined"!=typeof this.options_.modestbranding&&(a.modestbranding=this.options_.modestbranding),"undefined"!=typeof this.options_.playlist&&(a.playlist=this.options_.playlist),"undefined"!=typeof this.options_.playsinline&&(a.playsinline=this.options_.playsinline),"undefined"!=typeof this.options_.rel&&(a.rel=this.options_.rel),"undefined"!=typeof this.options_.showinfo&&(a.showinfo=this.options_.showinfo),"undefined"!=typeof this.options_.start&&(a.start=this.options_.start),"undefined"!=typeof this.options_.theme&&(a.theme=this.options_.theme),"undefined"!=typeof this.options_.customVars){var b=this.options_.customVars;Object.keys(b).forEach(function(c){a[c]=b[c]})}this.activeVideoId=this.url?this.url.videoId:null,this.activeList=a.list,this.ytPlayer=new YT.Player(this.options_.techId,{videoId:this.activeVideoId,playerVars:a,events:{onReady:this.onPlayerReady.bind(this),onPlaybackQualityChange:this.onPlayerPlaybackQualityChange.bind(this),onPlaybackRateChange:this.onPlayerPlaybackRateChange.bind(this),onStateChange:this.onPlayerStateChange.bind(this),onVolumeChange:this.onPlayerVolumeChange.bind(this),onError:this.onPlayerError.bind(this)}})},onPlayerReady:function(){this.options_.muted&&this.ytPlayer.mute();var a=this.ytPlayer.getAvailablePlaybackRates();a.length>1&&(this.featuresPlaybackRate=!0),this.playerReady_=!0,this.triggerReady(),this.playOnReady?this.play():this.cueOnReady&&(this.cueVideoById_(this.url.videoId),this.activeVideoId=this.url.videoId)},onPlayerPlaybackQualityChange:function(){},onPlayerPlaybackRateChange:function(){this.trigger("ratechange")},onPlayerStateChange:function(a){var b=a.data;if(b!==this.lastState&&!this.errorNumber)switch(this.lastState=b,b){case-1:this.trigger("loadstart"),this.trigger("loadedmetadata"),this.trigger("durationchange"),this.trigger("ratechange");break;case YT.PlayerState.ENDED:this.trigger("ended");break;case YT.PlayerState.PLAYING:this.trigger("timeupdate"),this.trigger("durationchange"),this.trigger("playing"),this.trigger("play"),this.isSeeking&&this.onSeeked();break;case YT.PlayerState.PAUSED:this.trigger("canplay"),this.isSeeking?this.onSeeked():this.trigger("pause");break;case YT.PlayerState.BUFFERING:this.player_.trigger("timeupdate"),this.player_.trigger("waiting")}},onPlayerVolumeChange:function(){this.trigger("volumechange")},onPlayerError:function(a){this.errorNumber=a.data,this.trigger("pause"),this.trigger("error")},error:function(){var a=1e3+this.errorNumber;switch(this.errorNumber){case 5:return{code:a,message:"Error while trying to play the video"};case 2:case 100:return{code:a,message:"Unable to find the video"};case 101:case 150:return{code:a,message:"Playback on other Websites has been disabled by the video owner."}}return{code:a,message:"YouTube unknown error ("+this.errorNumber+")"}},loadVideoById_:function(a){var b={videoId:a};this.options_.start&&(b.startSeconds=this.options_.start),this.options_.end&&(b.endEnd=this.options_.end),this.ytPlayer.loadVideoById(b)},cueVideoById_:function(a){var b={videoId:a};this.options_.start&&(b.startSeconds=this.options_.start),this.options_.end&&(b.endEnd=this.options_.end),this.ytPlayer.cueVideoById(b)},src:function(a){return a&&this.setSrc({src:a}),this.source},poster:function(){return e?null:this.poster_},setPoster:function(a){this.poster_=a},setSrc:function(a){a&&a.src&&(delete this.errorNumber,this.source=a,this.url=g.parseUrl(a.src),this.options_.poster||this.url.videoId&&(this.poster_="https://img.youtube.com/vi/"+this.url.videoId+"/0.jpg",this.trigger("posterchange"),this.checkHighResPoster()),this.options_.autoplay&&!e?this.isReady_?this.play():this.playOnReady=!0:this.activeVideoId!==this.url.videoId&&(this.isReady_?(this.cueVideoById_(this.url.videoId),this.activeVideoId=this.url.videoId):this.cueOnReady=!0))},autoplay:function(){return this.options_.autoplay},setAutoplay:function(a){this.options_.autoplay=a},loop:function(){return this.options_.loop},setLoop:function(a){this.options_.loop=a},play:function(){this.url&&this.url.videoId&&(this.wasPausedBeforeSeek=!1,this.isReady_?(this.url.listId&&(this.activeList===this.url.listId?this.ytPlayer.playVideo():(this.ytPlayer.loadPlaylist(this.url.listId),this.activeList=this.url.listId)),this.activeVideoId===this.url.videoId?this.ytPlayer.playVideo():(this.loadVideoById_(this.url.videoId),this.activeVideoId=this.url.videoId)):(this.trigger("waiting"),this.playOnReady=!0))},pause:function(){this.ytPlayer&&this.ytPlayer.pauseVideo()},paused:function(){return!this.ytPlayer||this.lastState!==YT.PlayerState.PLAYING&&this.lastState!==YT.PlayerState.BUFFERING},currentTime:function(){return this.ytPlayer?this.ytPlayer.getCurrentTime():0},setCurrentTime:function(a){this.lastState===YT.PlayerState.PAUSED&&(this.timeBeforeSeek=this.currentTime()),this.isSeeking||(this.wasPausedBeforeSeek=this.paused()),this.ytPlayer.seekTo(a,!0),this.trigger("timeupdate"),this.trigger("seeking"),this.isSeeking=!0,this.lastState===YT.PlayerState.PAUSED&&this.timeBeforeSeek!==a&&(clearInterval(this.checkSeekedInPauseInterval),this.checkSeekedInPauseInterval=setInterval(function(){this.lastState===YT.PlayerState.PAUSED&&this.isSeeking?this.currentTime()!==this.timeBeforeSeek&&(this.trigger("timeupdate"),this.onSeeked()):clearInterval(this.checkSeekedInPauseInterval)}.bind(this),250))},seeking:function(){return this.isSeeking},seekable:function(){return this.ytPlayer?a.createTimeRange(0,this.ytPlayer.getDuration()):a.createTimeRange()},onSeeked:function(){clearInterval(this.checkSeekedInPauseInterval),this.isSeeking=!1,this.wasPausedBeforeSeek&&this.pause(),this.trigger("seeked")},playbackRate:function(){return this.ytPlayer?this.ytPlayer.getPlaybackRate():1},setPlaybackRate:function(a){this.ytPlayer&&this.ytPlayer.setPlaybackRate(a)},duration:function(){return this.ytPlayer?this.ytPlayer.getDuration():0},currentSrc:function(){return this.source&&this.source.src},ended:function(){return!!this.ytPlayer&&this.lastState===YT.PlayerState.ENDED},volume:function(){return this.ytPlayer?this.ytPlayer.getVolume()/100:1},setVolume:function(a){this.ytPlayer&&this.ytPlayer.setVolume(100*a)},muted:function(){return!!this.ytPlayer&&this.ytPlayer.isMuted()},setMuted:function(a){this.ytPlayer&&(this.muted(!0),a?this.ytPlayer.mute():this.ytPlayer.unMute(),this.setTimeout(function(){this.trigger("volumechange")},50))},buffered:function(){if(!this.ytPlayer||!this.ytPlayer.getVideoLoadedFraction)return a.createTimeRange();var b=this.ytPlayer.getVideoLoadedFraction()*this.ytPlayer.getDuration();return a.createTimeRange(0,b)},preload:function(){},load:function(){},reset:function(){},supportsFullScreen:function(){return!0},checkHighResPoster:function(){var a="https://img.youtube.com/vi/"+this.url.videoId+"/maxresdefault.jpg";try{var b=new Image;b.onload=function(){if("naturalHeight"in b){if(b.naturalHeight<=90||b.naturalWidth<=120)return}else if(b.height<=90||b.width<=120)return;this.poster_=a,this.trigger("posterchange")}.bind(this),b.onerror=function(){},b.src=a}catch(c){}}});g.isSupported=function(){return!0},g.canPlaySource=function(a){return g.canPlayType(a.type)},g.canPlayType=function(a){return"video/youtube"===a},g.parseUrl=function(a){var b={videoId:null},c=/^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/,d=a.match(c);d&&11===d[2].length&&(b.videoId=d[2]);var e=/[?&]list=([^#\&\?]+)/;return d=a.match(e),d&&d[1]&&(b.listId=d[1]),b},g.apiReadyQueue=[],"undefined"!=typeof document&&(c("https://www.youtube.com/iframe_api",b),d()),"undefined"!=typeof a.registerTech?a.registerTech("Youtube",g):a.registerComponent("Youtube",g)});