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

1 line
5.6 KiB
JavaScript
Raw Normal View History

2017-04-27 10:54:54 -07:00
define(["require","events","browser","embyRouter","loading"],function(require,events,browser,embyRouter,loading){"use strict";return function(){function setCurrentSrc(elem,options){return new Promise(function(resolve,reject){require(["queryString"],function(queryString){currentSrc=options.url;var params=queryString.parse(options.url.split("?")[1]);if(window.onYouTubeIframeAPIReady=function(){currentYoutubePlayer=new YT.Player("player",{height:videoDialog.offsetHeight,width:videoDialog.offsetWidth,videoId:params.v,events:{onReady:onPlayerReady,onStateChange:function(event){event.data===YT.PlayerState.PLAYING?onPlaying(options,resolve):event.data===YT.PlayerState.ENDED?onEnded():event.data===YT.PlayerState.PAUSED&&onPause()}},playerVars:{controls:0,enablejsapi:1,modestbranding:1,rel:0,showinfo:0,fs:0,playsinline:1}}),window.removeEventListener("resize",onVideoResize),window.addEventListener("resize",onVideoResize),window.removeEventListener("orientationChange",onVideoResize),window.addEventListener("orientationChange",onVideoResize)},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 onVideoResize(){var player=currentYoutubePlayer,dlg=videoDialog;player&&dlg&&player.setSize(dlg.offsetWidth,dlg.offsetHeight)}function onPlayerReady(event){event.target.playVideo()}function onEnded(){onEndedInternal(!0)}function clearTimeUpdateInterval(){timeUpdateInterval&&clearInterval(timeUpdateInterval),timeUpdateInterval=null}function onEndedInternal(triggerEnded){if(clearTimeUpdateInterval(),window.removeEventListener("resize",onVideoResize),window.removeEventListener("orientationChange",onVideoResize),triggerEnded){var stopInfo={src:currentSrc};events.trigger(self,"stopped",[stopInfo])}currentSrc=null,currentYoutubePlayer&&currentYoutubePlayer.destroy(),currentYoutubePlayer=null}function onTimeUpdate(e){events.trigger(self,"timeupdate")}function onPlaying(playOptions,resolve){started||(started=!0,resolve(),clearTimeUpdateInterval(),timeUpdateInterval=setInterval(onTimeUpdate,500),playOptions.fullscreen?embyRouter.showVideoOsd().then(function(){videoDialog.classList.remove("onTop")}):(embyRouter.setTransparency("backdrop"),videoDialog.classList.remove("onTop")),require(["loading"],function(loading){loading.hide()})),events.trigger(self,"playing")}function onPause(){events.trigger(self,"pause")}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(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),videoDialog=dlg,options.fullscreen&&dlg.animate&&!browser.slow?zoomIn(dlg,1).onfinish=function(){resolve(videoElement)}:resolve(videoElement)})})}var self=this;self.name="Youtube Player",self.type="mediaplayer",self.id="youtubeplayer",self.priority=1;var videoDialog,currentSrc,currentYoutubePlayer,timeUpdateInterval,started=!1;self.canPlayMediaType=function(mediaType){return mediaType=(mediaType||"").toLowerCase(),"audio"===mediaType||"video"===mediaType},self.canPlayItem=function(item){return!1},self.canPlayUrl=function(url){return url.toLowerCase().indexOf("youtube.com")!==-1},self.getDeviceProfile=function(){return Promise.resolve({})},self.currentSrc=function(){return currentSrc},self.play=function(options){return started=!1,createMediaElement(options).then(function(elem){return setCurrentSrc(elem,options)})},se