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

1 line
6.9 KiB
JavaScript
Raw Normal View History

2017-05-31 12:19:57 -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()}))}function setCurrentSrc(instance,elem,options){return new Promise(function(resolve,reject){require(["queryString"],function(queryString){instance._currentSrc=options.url;var params=queryString.parse(options.url.split("?")[1]);if(window.onYouTubeIframeAPIReady=function(){instance.currentYoutubePlayer=new YT.Player("player",{height:instance.videoDialog.offsetHeight,width:instance.videoDialog.offsetWidth,videoId:params.v,events:{onReady:onPlayerReady,onStateChange:function(event){event.data===YT.PlayerState.PLAYING?onPlaying(instance,options,resolve):event.data===YT.PlayerState.ENDED?onEndedInternal(instance):event.data===YT.PlayerState.PAUSED&&events.trigger(instance,"pause")}},playerVars:{controls:0,enablejsapi:1,modestbranding:1,rel:0,showinfo:0,fs:0,playsinline:1}});var resizeListener=instance.resizeListener;resizeListener?(window.removeEventListener("resize",resizeListener),window.addEventListener("resize",resizeListener)):resizeListener=instance.resizeListener=onVideoResize.bind(instance),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 YoutubePlayer(){this.name="Youtube Player",this.type="mediaplayer",this.id="youtubeplayer",this.priority=1}return YoutubePlayer.prototype.play=function(options){this.started=!1;var instance=this;return createMediaElement(this,options).then(function(elem){retur