Proyectos de Subversion Moodle

Rev

Autoría | Ultima modificación | Ver Log |

!function(root,factory){if("object"==typeof exports&&"undefined"!=typeof module){var videojs=require("video.js");module.exports=factory(videojs.default||videojs)}else"function"==typeof define&&define.amd?define("media_videojs/Youtube-lazy",["media_videojs/video-lazy"],(function(videojs){return root.Youtube=factory(videojs)})):root.Youtube=factory(root.videojs)}(window,(function(videojs){var css,head,style,src,callback,loaded,tag,firstScriptTag,_isOnMobile=videojs.browser.IS_IOS||videojs.browser.IS_NATIVE_ANDROID,Tech=videojs.getTech("Tech");class Youtube extends Tech{constructor(options,ready){super(options,ready),this.setPoster(options.poster),this.setSrc(this.options_.source,!0),this.setTimeout(function(){this.el_&&(this.el_.parentNode.className+=" vjs-youtube",_isOnMobile&&(this.el_.parentNode.className+=" vjs-youtube-mobile"),Youtube.isApiReady?this.initYTPlayer():Youtube.apiReadyQueue.push(this))}.bind(this))}dispose(){if(this.ytPlayer)this.ytPlayer.stopVideo&&this.ytPlayer.stopVideo(),this.ytPlayer.destroy&&this.ytPlayer.destroy();else{var index=Youtube.apiReadyQueue.indexOf(this);-1!==index&&Youtube.apiReadyQueue.splice(index,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_),Tech.prototype.dispose.call(this)}createEl(){var div=document.createElement("div");div.setAttribute("id",this.options_.techId),div.setAttribute("style","width:100%;height:100%;top:0;left:0;position:absolute"),div.setAttribute("class","vjs-tech");var divWrapper=document.createElement("div");if(divWrapper.appendChild(div),!_isOnMobile&&!this.options_.ytControls){var divBlocker=document.createElement("div");divBlocker.setAttribute("class","vjs-iframe-blocker"),divBlocker.setAttribute("style","position:absolute;top:0;left:0;width:100%;height:100%"),divBlocker.onclick=function(){this.pause()}.bind(this),divWrapper.appendChild(divBlocker)}return divWrapper}initYTPlayer(){var playerVars={controls:0,modestbranding:1,rel:0,showinfo:0,loop:this.options_.loop?1:0};if(void 0!==this.options_.autohide&&(playerVars.autohide=this.options_.autohide),void 0!==this.options_.cc_load_policy&&(playerVars.cc_load_policy=this.options_.cc_load_policy),void 0!==this.options_.ytControls&&(playerVars.controls=this.options_.ytControls),void 0!==this.options_.disablekb&&(playerVars.disablekb=this.options_.disablekb),void 0!==this.options_.color&&(playerVars.color=this.options_.color),playerVars.controls?void 0!==this.options_.fs&&(playerVars.fs=this.options_.fs):playerVars.fs=0,-1!==this.options_.source.src.indexOf("end=")){var srcEndTime=this.options_.source.src.match(/end=([0-9]*)/);this.options_.end=parseInt(srcEndTime[1])}if(void 0!==this.options_.end&&(playerVars.end=this.options_.end),void 0!==this.options_.hl?playerVars.hl=this.options_.hl:void 0!==this.options_.language&&(playerVars.hl=this.options_.language.substr(0,2)),void 0!==this.options_.iv_load_policy&&(playerVars.iv_load_policy=this.options_.iv_load_policy),void 0!==this.options_.list?playerVars.list=this.options_.list:this.url&&void 0!==this.url.listId&&(playerVars.list=this.url.listId),void 0!==this.options_.listType&&(playerVars.listType=this.options_.listType),void 0!==this.options_.modestbranding&&(playerVars.modestbranding=this.options_.modestbranding),void 0!==this.options_.playlist&&(playerVars.playlist=this.options_.playlist),void 0!==this.options_.playsinline&&(playerVars.playsinline=this.options_.playsinline),void 0!==this.options_.rel&&(playerVars.rel=this.options_.rel),void 0!==this.options_.showinfo&&(playerVars.showinfo=this.options_.showinfo),-1!==this.options_.source.src.indexOf("start=")){var srcStartTime=this.options_.source.src.match(/start=([0-9]*)/);this.options_.start=parseInt(srcStartTime[1])}if(void 0!==this.options_.start&&(playerVars.start=this.options_.start),void 0!==this.options_.theme&&(playerVars.theme=this.options_.theme),void 0!==this.options_.customVars){var customVars=this.options_.customVars;Object.keys(customVars).forEach((function(key){playerVars[key]=customVars[key]}))}this.activeVideoId=this.url?this.url.videoId:null,this.activeList=playerVars.list;var playerConfig={videoId:this.activeVideoId,playerVars:playerVars,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)}};void 0!==this.options_.enablePrivacyEnhancedMode&&this.options_.enablePrivacyEnhancedMode&&(playerConfig.host="https://www.youtube-nocookie.com"),this.ytPlayer=new YT.Player(this.options_.techId,playerConfig)}onPlayerReady(){this.options_.muted&&this.ytPlayer.mute(),this.ytPlayer.getAvailablePlaybackRates().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(){}onPlayerPlaybackRateChange(){this.trigger("ratechange")}onPlayerStateChange(e){var state=e.data;if(state!==this.lastState&&!this.errorNumber)switch(this.lastState=state,state){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(){this.trigger("volumechange")}onPlayerError(e){this.errorNumber=e.data,this.trigger("pause"),this.trigger("error")}error(){var code=1e3+this.errorNumber;switch(this.errorNumber){case 5:return{code:code,message:"Error while trying to play the video"};case 2:case 100:return{code:code,message:"Unable to find the video"};case 101:case 150:return{code:code,message:"Playback on other Websites has been disabled by the video owner."}}return{code:code,message:"YouTube unknown error ("+this.errorNumber+")"}}loadVideoById_(id){var options={videoId:id};this.options_.start&&(options.startSeconds=this.options_.start),this.options_.end&&(options.endSeconds=this.options_.end),this.ytPlayer.loadVideoById(options)}cueVideoById_(id){var options={videoId:id};this.options_.start&&(options.startSeconds=this.options_.start),this.options_.end&&(options.endSeconds=this.options_.end),this.ytPlayer.cueVideoById(options)}src(src){return src&&this.setSrc({src:src}),this.source}poster(){return _isOnMobile?null:this.poster_}setPoster(poster){this.poster_=poster}setSrc(source){source&&source.src&&(delete this.errorNumber,this.source=source,this.url=Youtube.parseUrl(source.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&&!_isOnMobile?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(){return this.options_.autoplay}setAutoplay(val){this.options_.autoplay=val}loop(){return this.options_.loop}setLoop(val){this.options_.loop=val}play(){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(){this.ytPlayer&&this.ytPlayer.pauseVideo()}paused(){return!this.ytPlayer||this.lastState!==YT.PlayerState.PLAYING&&this.lastState!==YT.PlayerState.BUFFERING}currentTime(){return this.ytPlayer?this.ytPlayer.getCurrentTime():0}setCurrentTime(seconds){this.lastState===YT.PlayerState.PAUSED&&(this.timeBeforeSeek=this.currentTime()),this.isSeeking||(this.wasPausedBeforeSeek=this.paused()),this.ytPlayer.seekTo(seconds,!0),this.trigger("timeupdate"),this.trigger("seeking"),this.isSeeking=!0,this.lastState===YT.PlayerState.PAUSED&&this.timeBeforeSeek!==seconds&&(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(){return this.isSeeking}seekable(){return this.ytPlayer?videojs.createTimeRange(0,this.ytPlayer.getDuration()):videojs.createTimeRange()}onSeeked(){clearInterval(this.checkSeekedInPauseInterval),this.isSeeking=!1,this.wasPausedBeforeSeek&&this.pause(),this.trigger("seeked")}playbackRate(){return this.ytPlayer?this.ytPlayer.getPlaybackRate():1}setPlaybackRate(suggestedRate){this.ytPlayer&&this.ytPlayer.setPlaybackRate(suggestedRate)}duration(){return this.ytPlayer?this.ytPlayer.getDuration():0}currentSrc(){return this.source&&this.source.src}ended(){return!!this.ytPlayer&&this.lastState===YT.PlayerState.ENDED}volume(){return this.ytPlayer?this.ytPlayer.getVolume()/100:1}setVolume(percentAsDecimal){this.ytPlayer&&this.ytPlayer.setVolume(100*percentAsDecimal)}muted(){return!!this.ytPlayer&&this.ytPlayer.isMuted()}setMuted(mute){this.ytPlayer&&(this.muted(!0),mute?this.ytPlayer.mute():this.ytPlayer.unMute(),this.setTimeout((function(){this.trigger("volumechange")}),50))}buffered(){if(!this.ytPlayer||!this.ytPlayer.getVideoLoadedFraction)return videojs.createTimeRange();var bufferedEnd=this.ytPlayer.getVideoLoadedFraction()*this.ytPlayer.getDuration();return videojs.createTimeRange(0,bufferedEnd)}preload(){}load(){}reset(){}networkState(){if(!this.ytPlayer)return 0;switch(this.ytPlayer.getPlayerState()){case-1:return 0;case 3:return 2;default:return 1}}readyState(){if(!this.ytPlayer)return 0;switch(this.ytPlayer.getPlayerState()){case-1:return 0;case 5:return 1;case 3:return 2;default:return 4}}supportsFullScreen(){return document.fullscreenEnabled||document.webkitFullscreenEnabled||document.mozFullScreenEnabled||document.msFullscreenEnabled}checkHighResPoster(){var uri="https://img.youtube.com/vi/"+this.url.videoId+"/maxresdefault.jpg";try{var image=new Image;image.onload=function(){if("naturalHeight"in image){if(image.naturalHeight<=90||image.naturalWidth<=120)return}else if(image.height<=90||image.width<=120)return;this.poster_=uri,this.trigger("posterchange")}.bind(this),image.onerror=function(){},image.src=uri}catch(e){}}}Youtube.isSupported=function(){return!0},Youtube.canPlaySource=function(e){return Youtube.canPlayType(e.type)},Youtube.canPlayType=function(e){return"video/youtube"===e},Youtube.parseUrl=function(url){var result={videoId:null},match=url.match(/^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/);match&&11===match[2].length&&(result.videoId=match[2]);return(match=url.match(/[?&]list=([^#\&\?]+)/))&&match[1]&&(result.listId=match[1]),result},Youtube.apiReadyQueue=[],"undefined"!=typeof document&&(src="https://www.youtube.com/iframe_api",callback=function(){YT.ready((function(){Youtube.isApiReady=!0;for(var i=0;i<Youtube.apiReadyQueue.length;++i)Youtube.apiReadyQueue[i].initYTPlayer()}))},loaded=!1,tag=document.createElement("script"),(firstScriptTag=document.getElementsByTagName("script")[0])&&(firstScriptTag.parentNode.insertBefore(tag,firstScriptTag),tag.onload=function(){loaded||(loaded=!0,callback())},tag.onreadystatechange=function(){loaded||"complete"!==this.readyState&&"loaded"!==this.readyState||(loaded=!0,callback())},tag.src=src),css=".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; }",head=document.head||document.getElementsByTagName("head")[0],(style=document.createElement("style")).type="text/css",style.styleSheet?style.styleSheet.cssText=css:style.appendChild(document.createTextNode(css)),head.appendChild(style)),void 0!==videojs.registerTech?videojs.registerTech("Youtube",Youtube):videojs.registerComponent("Youtube",Youtube)}));

//# sourceMappingURL=Youtube-lazy.min.js.map