mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
implement chrome media session api
This commit is contained in:
parent
7b427e4581
commit
bb7710e105
6 changed files with 8 additions and 7 deletions
|
@ -1 +1 @@
|
||||||
define(["layoutManager","browser","dom","css!./emby-input","registerElement"],function(layoutManager,browser,dom){"use strict";function onChange(){var label=this.labelElement;if(this.value)label.classList.remove("inputLabel-float");else{var instanceSupportsFloat=supportsFloatingLabel&&"date"!==this.type&&"time"!==this.type;instanceSupportsFloat&&label.classList.add("inputLabel-float")}}var EmbyInputPrototype=Object.create(HTMLInputElement.prototype),inputId=0,supportsFloatingLabel=!1;if(Object.getOwnPropertyDescriptor&&Object.defineProperty){var descriptor=Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"value");if(descriptor&&descriptor.configurable){var baseSetMethod=descriptor.set;descriptor.set=function(value){baseSetMethod.call(this,value),this.dispatchEvent(new CustomEvent("valueset",{bubbles:!1,cancelable:!1}))},Object.defineProperty(HTMLInputElement.prototype,"value",descriptor),supportsFloatingLabel=!0}}EmbyInputPrototype.createdCallback=function(){if(this.id||(this.id="embyinput"+inputId,inputId++),!this.classList.contains("emby-input")){this.classList.add("emby-input");var parentNode=this.parentNode,document=this.ownerDocument,label=document.createElement("label");label.innerHTML=this.getAttribute("label")||"",label.classList.add("inputLabel"),label.classList.add("inputLabelUnfocused"),label.htmlFor=this.id,parentNode.insertBefore(label,this),this.labelElement=label;var div=document.createElement("div");div.classList.add("emby-input-selectionbar"),parentNode.insertBefore(div,this.nextSibling),dom.addEventListener(this,"focus",function(){onChange.call(this),label.classList.add("inputLabelFocused"),label.classList.remove("inputLabelUnfocused")},{passive:!0}),dom.addEventListener(this,"blur",function(){onChange.call(this),label.classList.remove("inputLabelFocused"),label.classList.add("inputLabelUnfocused")},{passive:!0}),dom.addEventListener(this,"change",onChange,{passive:!0}),dom.addEventListener(this,"input",onChange,{passive:!0}),dom.addEventListener(this,"valueset",onChange,{passive:!0})}},EmbyInputPrototype.attachedCallback=function(){this.labelElement.htmlFor=this.id,onChange.call(this)},EmbyInputPrototype.label=function(text){this.labelElement.innerHTML=text},document.registerElement("emby-input",{prototype:EmbyInputPrototype,extends:"input"})});
|
define(["layoutManager","browser","dom","css!./emby-input","registerElement"],function(layoutManager,browser,dom){"use strict";function onChange(){var label=this.labelElement;if(this.value)label.classList.remove("inputLabel-float");else{var instanceSupportsFloat=supportsFloatingLabel&&"date"!==this.type&&"time"!==this.type;instanceSupportsFloat&&label.classList.add("inputLabel-float")}}var EmbyInputPrototype=Object.create(HTMLInputElement.prototype),inputId=0,supportsFloatingLabel=!1;if(Object.getOwnPropertyDescriptor&&Object.defineProperty){var descriptor=Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"value");if(descriptor&&descriptor.configurable){var baseSetMethod=descriptor.set;descriptor.set=function(value){baseSetMethod.call(this,value),this.dispatchEvent(new CustomEvent("valueset",{bubbles:!1,cancelable:!1}))},Object.defineProperty(HTMLInputElement.prototype,"value",descriptor),supportsFloatingLabel=!0}}EmbyInputPrototype.createdCallback=function(){if(this.id||(this.id="embyinput"+inputId,inputId++),!this.classList.contains("emby-input")){this.classList.add("emby-input");var parentNode=this.parentNode,document=this.ownerDocument,label=document.createElement("label");label.innerHTML=this.getAttribute("label")||"",label.classList.add("inputLabel"),label.classList.add("inputLabelUnfocused"),label.htmlFor=this.id,parentNode.insertBefore(label,this),this.labelElement=label;var div=document.createElement("div");div.classList.add("emby-input-selectionbar"),parentNode.insertBefore(div,this.nextSibling),dom.addEventListener(this,"focus",function(){onChange.call(this),document.attachIME&&document.attachIME(this),label.classList.add("inputLabelFocused"),label.classList.remove("inputLabelUnfocused")},{passive:!0}),dom.addEventListener(this,"blur",function(){onChange.call(this),label.classList.remove("inputLabelFocused"),label.classList.add("inputLabelUnfocused")},{passive:!0}),dom.addEventListener(this,"change",onChange,{passive:!0}),dom.addEventListener(this,"input",onChange,{passive:!0}),dom.addEventListener(this,"valueset",onChange,{passive:!0})}},EmbyInputPrototype.attachedCallback=function(){this.labelElement.htmlFor=this.id,onChange.call(this)},EmbyInputPrototype.label=function(text){this.labelElement.innerHTML=text},document.registerElement("emby-input",{prototype:EmbyInputPrototype,extends:"input"})});
|
1
dashboard-ui/bower_components/emby-webcomponents/playback/mediasession.js
vendored
Normal file
1
dashboard-ui/bower_components/emby-webcomponents/playback/mediasession.js
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
define(["playbackManager","nowPlayingHelper","events","connectionManager"],function(playbackManager,nowPlayingHelper,events,connectionManager){"use strict";function seriesImageUrl(item,options){if("Episode"!==item.Type)return null;if(options=options||{},options.type=options.type||"Primary","Primary"===options.type&&item.SeriesPrimaryImageTag)return options.tag=item.SeriesPrimaryImageTag,connectionManager.getApiClient(item.ServerId).getScaledImageUrl(item.SeriesId,options);if("Thumb"===options.type){if(item.SeriesThumbImageTag)return options.tag=item.SeriesThumbImageTag,connectionManager.getApiClient(item.ServerId).getScaledImageUrl(item.SeriesId,options);if(item.ParentThumbImageTag)return options.tag=item.ParentThumbImageTag,connectionManager.getApiClient(item.ServerId).getScaledImageUrl(item.ParentThumbItemId,options)}return null}function imageUrl(item,options){return options=options||{},options.type=options.type||"Primary",item.ImageTags&&item.ImageTags[options.type]?(options.tag=item.ImageTags[options.type],connectionManager.getApiClient(item.ServerId).getScaledImageUrl(item.Id,options)):item.AlbumId&&item.AlbumPrimaryImageTag?(options.tag=item.AlbumPrimaryImageTag,connectionManager.getApiClient(item.ServerId).getScaledImageUrl(item.AlbumId,options)):null}function pushImageUrl(item,height,list){var imageOptions={height:height},url=seriesImageUrl(item,imageOptions)||imageUrl(item,imageOptions);url&&list.push({src:url,sizes:height+"x"+height})}function getImageUrls(item){var list=[];return pushImageUrl(item,96,list),pushImageUrl(item,128,list),pushImageUrl(item,192,list),pushImageUrl(item,256,list),pushImageUrl(item,384,list),pushImageUrl(item,512,list),list}function updatePlayerState(player,state,eventName){var item=state.NowPlayingItem;if(!item)return void hideMediaControls();var playState=state.PlayState||{},parts=nowPlayingHelper.getNowPlayingNames(item),artist=1===parts.length?"":parts[0].text,title=parts[parts.length-1].text,isVideo="Video"===item.MediaType;if(isVideo&&parts.length>1){var temp=artist;artist=title,title=temp}var albumArtist;item.AlbumArtists&&item.AlbumArtists[0]&&(albumArtist=item.AlbumArtists[0].Name);var album=item.Album||"",itemId=item.Id,duration=parseInt(item.RunTimeTicks?item.RunTimeTicks/1e4:0),currentTime=parseInt(playState.PositionTicks?playState.PositionTicks/1e4:0),isPaused=playState.IsPaused||!1;playState.CanSeek||!1;navigator.mediaSession.metadata=new MediaMetadata({title:title,artist:artist,album:album,artwork:getImageUrls(item),albumArtist:albumArtist,currentTime:currentTime,duration:duration,paused:isPaused,itemId:itemId,mediaType:item.MediaType})}function onGeneralEvent(e,state){var player=this;playbackManager.getPlayerState(player).then(function(state){updatePlayerState(player,state,e.type)})}function onStateChanged(e,state){var player=this;updatePlayerState(player,state,"statechange")}function onPlaybackStart(e,state){console.log("nowplaying event: "+e.type);var player=this;updatePlayerState(player,state,e.type)}function onPlaybackStopped(e,state){console.log("nowplaying event: "+e.type);hideMediaControls()}function releaseCurrentPlayer(){currentPlayer&&(events.off(currentPlayer,"playbackstart",onPlaybackStart),events.off(currentPlayer,"playbackstop",onPlaybackStopped),events.off(currentPlayer,"play",onGeneralEvent),events.off(currentPlayer,"pause",onGeneralEvent),events.off(currentPlayer,"statechange",onStateChanged),events.off(currentPlayer,"timeupdate",onGeneralEvent),currentPlayer=null,hideMediaControls())}function hideMediaControls(){navigator.mediaSession.metadata=null}function bindToPlayer(player){releaseCurrentPlayer(),player&&(currentPlayer=player,console.log("binding remotecontrols to "+player.name),playbackManager.getPlayerState(player).then(function(state){updatePlayerState(player,state,"init")}),events.on(currentPlayer,"playbackstart",onPlaybackStart),events.on(currentPlayer,"playbackstop",onPlaybackStopped),events.on(currentPlayer,"play",onGeneralEvent),events.on(currentPlayer,"pause",onGeneralEvent),events.on(currentPlayer,"statechange",onStateChanged),events.on(currentPlayer,"timeupdate",onGeneralEvent))}function execute(name){playbackManager[name](currentPlayer)}var currentPlayer;console.log("binding remotecontrols to playbackManager"),navigator.mediaSession.setActionHandler("previoustrack",function(){execute("previousChapter")}),navigator.mediaSession.setActionHandler("nexttrack",function(){execute("nextChapter")}),navigator.mediaSession.setActionHandler("play",function(){execute("unpause")}),navigator.mediaSession.setActionHandler("pause",function(){execute("pause")}),navigator.mediaSession.setActionHandler("seekbackward",function(){execute("rewind")}),navigator.mediaSession.setActionHandler("seekforward",function(){execute("fastForward")}),events.on(playbackManager,"playerchange",function(){bindToPlayer(playbackManager.getCurrentPlayer())}),bindToPlayer(playbackManager.getCurrentPlayer())});
|
File diff suppressed because one or more lines are too long
|
@ -53,7 +53,7 @@
|
||||||
|
|
||||||
<div class="checkboxContainer checkboxContainer-withDescription chkAutomaticallyGroupSeriesContainer hide">
|
<div class="checkboxContainer checkboxContainer-withDescription chkAutomaticallyGroupSeriesContainer hide">
|
||||||
<label>
|
<label>
|
||||||
<input type="checkbox" is="emby-checkbox" class="chkAutomaticallyGroupSeries" />
|
<input type="checkbox" is="emby-checkbox" class="chkAutomaticallyGroupSeries" checked />
|
||||||
<span>${OptionAutomaticallyGroupSeries}</span>
|
<span>${OptionAutomaticallyGroupSeries}</span>
|
||||||
</label>
|
</label>
|
||||||
<div class="fieldDescription checkboxFieldDescription">${OptionAutomaticallyGroupSeriesHelp}</div>
|
<div class="fieldDescription checkboxFieldDescription">${OptionAutomaticallyGroupSeriesHelp}</div>
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue