jellyfin-web/dashboard-ui/bower_components/emby-webcomponents/youtubeplayer/plugin.js

1 line
6.9 KiB
JavaScript
Raw Normal View History

2017-04-28 15:31:47 -07:00
define(["require","events","browser","embyRouter","loading"],function(require,events,browser,embyRouter,loading){"use strict";function zoomIn(elem,iterations){var keyframes=[{transform:"scale3d(.2, .2, .2) ",opacity:".6",offset:0},{transform:"none",opacity:"1",offset:1}],timing={duration:240,iterations:iterations};return elem.animate(keyframes,timing)}function createMediaElement(instance,options){return new Promise(function(resolve,reject){var dlg=document.querySelector(".youtubePlayerContainer");dlg?resolve(dlg.querySelector("#player")):require(["css!./style"],function(){loading.show();var dlg=document.createElement("div");dlg.classList.add("youtubePlayerContainer"),options.fullscreen&&dlg.classList.add("onTop"),dlg.innerHTML='<div id="player"></div>';var videoElement=dlg.querySelector("#player");document.body.insertBefore(dlg,document.body.firstChild),instance.videoDialog=dlg,options.fullscreen&&dlg.animate&&!browser.slow?zoomIn(dlg,1).onfinish=function(){resolve(videoElement)}:resolve(videoElement)})})}function onVideoResize(){var instance=this,player=instance.currentYoutubePlayer,dlg=instance.videoDialog;player&&dlg&&player.setSize(dlg.offsetWidth,dlg.offsetHeight)}function clearTimeUpdateInterval(instance){instance.timeUpdateInterval&&clearInterval(instance.timeUpdateInterval),instance.timeUpdateInterval=null}function onEndedInternal(instance,triggerEnded){clearTimeUpdateInterval(instance);var resizeListener=instance.resizeListener;if(resizeListener&&(window.removeEventListener("resize",resizeListener),window.removeEventListener("orientationChange",resizeListener),instance.resizeListener=null),triggerEnded){var stopInfo={src:instance._currentSrc};events.trigger(instance,"stopped",[stopInfo])}instance._currentSrc=null,instance.currentYoutubePlayer&&instance.currentYoutubePlayer.destroy(),instance.currentYoutubePlayer=null}function onPlayerReady(event){event.target.playVideo()}function onTimeUpdate(e){events.trigger(this,"timeupdate")}function onPlaying(instance,playOptions,resolve){instance.started||(instance.started=!0,resolve(),clearTimeUpdateInterval(instance),instance.timeUpdateInterval=setInterval(onTimeUpdate.bind(instance),500),playOptions.fullscreen?embyRouter.showVideoOsd().then(function(){instance.videoDialog.classList.remove("onTop")}):(embyRouter.setTransparency("backdrop"),instance.videoDialog.classList.remove("onTop")),require(["loading"],function(loading){loading.hide()})),events.trigger(instance,"playing")}function YoutubePlayer(){function setCurrentSrc(elem,options){return new Promise(function(resolve,reject){require(["queryString"],function(queryString){self._currentSrc=options.url;var params=queryString.parse(options.url.split("?")[1]);if(window.onYouTubeIframeAPIReady=function(){self.currentYoutubePlayer=new YT.Player("player",{height:self.videoDialog.offsetHeight,width:self.videoDialog.offsetWidth,videoId:params.v,events:{onReady:onPlayerReady,onStateChange:function(event){event.data===YT.PlayerState.PLAYING?onPlaying(self,options,resolve):event.data===YT.PlayerState.ENDED?onEnded():event.data===YT.PlayerState.PAUSED&&events.trigger(self,"pause")}},playerVars:{controls:0,enablejsapi:1,modestbranding:1,rel:0,showinfo:0,fs:0,playsinline:1}});var resizeListener=self.resizeListener;resizeListener?(window.removeEventListener("resize",resizeListener),window.addEventListener("resize",resizeListener)):resizeListener=self.resizeListener=onVideoResize.bind(self),window.removeEventListener("orientationChange",resizeListener),window.addEventListener("orientationChange",resizeListener)},window.YT)window.onYouTubeIframeAPIReady();else{var tag=document.createElement("script");tag.src="https://www.youtube.com/iframe_api";var firstScriptTag=document.getElementsByTagName("script")[0];firstScriptTag.parentNode.insertBefore(tag,firstScriptTag)}})})}function onEnded(){onEndedInternal(self,!0)}var self=this;self.name="Youtube Player",self.type="mediaplayer",self.id="youtubeplayer",self.priority=1,self.play=function(options){return this.started=!1,createMediaElement(this,options).then(function(elem){return setCurrent