mirror of
https://github.com/jellyfin/jellyfin-web.git
synced 2024-11-19 03:48:18 -07:00
1 line
6.9 KiB
JavaScript
1 line
6.9 KiB
JavaScript
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 setCurrentSrc(elem,options)})}}return YoutubePlayer.prototype.stop=function(destroyPlayer,reportEnded){var src=this._currentSrc;return src&&(this.currentYoutubePlayer&&this.currentYoutubePlayer.stopVideo(),onEndedInternal(this,reportEnded),destroyPlayer&&this.destroy()),Promise.resolve()},YoutubePlayer.prototype.destroy=function(){embyRouter.setTransparency("none");var dlg=this.videoDialog;dlg&&(this.videoDialog=null,dlg.parentNode.removeChild(dlg))},YoutubePlayer.prototype.canPlayMediaType=function(mediaType){return mediaType=(mediaType||"").toLowerCase(),"audio"===mediaType||"video"===mediaType},YoutubePlayer.prototype.canPlayItem=function(item){return!1},YoutubePlayer.prototype.canPlayUrl=function(url){return url.toLowerCase().indexOf("youtube.com")!==-1},YoutubePlayer.prototype.getDeviceProfile=function(){return Promise.resolve({})},YoutubePlayer.prototype.currentSrc=function(){return this._currentSrc},YoutubePlayer.prototype.setSubtitleStreamIndex=function(index){},YoutubePlayer.prototype.canSetAudioStreamIndex=function(){return!1},YoutubePlayer.prototype.setAudioStreamIndex=function(index){},YoutubePlayer.prototype.currentTime=function(val){var currentYoutubePlayer=this.currentYoutubePlayer;if(currentYoutubePlayer)return null!=val?void currentYoutubePlayer.seekTo(val/1e3,!0):1e3*currentYoutubePlayer.getCurrentTime()},YoutubePlayer.prototype.duration=function(val){var currentYoutubePlayer=this.currentYoutubePlayer;return currentYoutubePlayer?1e3*currentYoutubePlayer.getDuration():null},YoutubePlayer.prototype.pause=function(){var currentYoutubePlayer=this.currentYoutubePlayer;if(currentYoutubePlayer){currentYoutubePlayer.pauseVideo();var instance=this;setTimeout(function(){events.trigger(instance,"pause")},200)}},YoutubePlayer.prototype.unpause=function(){var currentYoutubePlayer=this.currentYoutubePlayer;if(currentYoutubePlayer){currentYoutubePlayer.playVideo();var instance=this;setTimeout(function(){onPlaying(instance)},200)}},YoutubePlayer.prototype.paused=function(){var currentYoutubePlayer=this.currentYoutubePlayer;return!!currentYoutubePlayer&&(console.log(currentYoutubePlayer.getPlayerState()),2===currentYoutubePlayer.getPlayerState())},YoutubePlayer.prototype.volume=function(val){return null!=val?this.setVolume(val):this.getVolume()},YoutubePlayer.prototype.setVolume=function(val){var currentYoutubePlayer=this.currentYoutubePlayer;currentYoutubePlayer&&null!=val&¤tYoutubePlayer.setVolume(val)},YoutubePlayer.prototype.getVolume=function(){var currentYoutubePlayer=this.currentYoutubePlayer;if(currentYoutubePlayer)return currentYoutubePlayer.getVolume()},YoutubePlayer.prototype.setMute=function(mute){var currentYoutubePlayer=this.currentYoutubePlayer;mute?currentYoutubePlayer&¤tYoutubePlayer.mute():currentYoutubePlayer&¤tYoutubePlayer.unMute()},YoutubePlayer.prototype.isMuted=function(){var currentYoutubePlayer=this.currentYoutubePlayer;currentYoutubePlayer&¤tYoutubePlayer.isMuted()},YoutubePlayer}); |