@@ -2,58 +2,88 @@ import { css, html, LitElement, nothing } from 'lit';
22import { property } from 'lit/decorators.js' ;
33import MediaControlService from '../services/media-control-service' ;
44import Store from '../model/store' ;
5- import { CardConfig , MediaPlayerEntityFeature } from '../types' ;
6- import { mdiFastForward , mdiRewind , mdiVolumeMinus , mdiVolumePlus } from '@mdi/js' ;
5+ import { CardConfig } from '../types' ;
6+ import {
7+ mdiFastForward ,
8+ mdiPauseCircle ,
9+ mdiPlayBoxMultiple ,
10+ mdiPlayCircle ,
11+ mdiRewind ,
12+ mdiSkipNext ,
13+ mdiSkipPrevious ,
14+ mdiStopCircle ,
15+ mdiVolumeMinus ,
16+ mdiVolumePlus ,
17+ } from '@mdi/js' ;
718import { MediaPlayer } from '../model/media-player' ;
819import { until } from 'lit-html/directives/until.js' ;
920import { findPlayer } from '../utils/utils' ;
10-
11- const { SHUFFLE_SET , REPEAT_SET , PLAY , PAUSE , NEXT_TRACK , PREVIOUS_TRACK , BROWSE_MEDIA , STOP } =
12- MediaPlayerEntityFeature ;
21+ import MediaBrowseService from '../services/media-browse-service' ;
1322
1423class PlayerControls extends LitElement {
1524 @property ( { attribute : false } ) store ! : Store ;
1625 private config ! : CardConfig ;
1726 private activePlayer ! : MediaPlayer ;
1827 private mediaControlService ! : MediaControlService ;
28+ private mediaBrowseService ! : MediaBrowseService ;
1929 private volumePlayer ! : MediaPlayer ;
2030 private updateMemberVolumes ! : boolean ;
2131
2232 render ( ) {
2333 this . config = this . store . config ;
2434 this . activePlayer = this . store . activePlayer ;
2535 this . mediaControlService = this . store . mediaControlService ;
36+ this . mediaBrowseService = this . store . mediaBrowseService ;
2637 const noUpDown = ! ! this . config . showVolumeUpAndDownButtons && nothing ;
2738 const noFastForwardAndRewind = ! ! this . config . showFastForwardAndRewindButtons && nothing ;
39+ const noShuffle = ! this . config . hidePlayerControlShuffleButton && nothing ;
40+ const noPrev = ! this . config . hidePlayerControlPrevTrackButton && nothing ;
41+ const noNext = ! this . config . hidePlayerControlNextTrackButton && nothing ;
42+ const noRepeat = ! this . config . hidePlayerControlRepeatButton && nothing ;
43+ const noBrowse = ! ! this . config . showBrowseMediaInPlayerSection && nothing ;
44+
2845 this . volumePlayer = this . getVolumePlayer ( ) ;
2946 this . updateMemberVolumes = ! this . config . playerVolumeEntityId ;
30- const pauseOrStop = this . config . stopInsteadOfPause ? STOP : PAUSE ;
47+ const pauseOrStop = this . config . stopInsteadOfPause ? mdiStopCircle : mdiPauseCircle ;
48+ const playing = this . activePlayer . isPlaying ( ) ;
3149 return html `
3250 <div class= "main" id = "mediaControls" >
3351 <div class= "icons" >
3452 <div class= "flex-1" > </ div>
3553 <ha- icon- butto n hide= ${ noUpDown } @click = ${ this . volDown } .path = ${ mdiVolumeMinus } > </ ha- icon- butto n>
36- <sonos- ha - player . store = ${ this . store } .features = ${ this . showShuffle ( ) } > </ sonos- ha - player >
37- <sonos - ha- player . store = ${ this . store } .features = ${ this . showPrev ( ) } > </ sonos - ha- player >
54+ <sonos- shuffle hide = ${ noShuffle } .store = ${ this . store } > </ sonos- shuffle >
55+ < ha- icon - but to n hide = ${ noPrev } @click = ${ this . prev } .path = ${ mdiSkipPrevious } > </ ha- icon - but to n >
3856 <ha- icon- butto n hide= ${ noFastForwardAndRewind } @click = ${ this . rewind } .path = ${ mdiRewind } > </ ha- icon- butto n>
39- <sonos - ha- player . store = ${ this . store } .features = ${ [ PLAY , pauseOrStop ] } class= "big-icon" > </ sonos - ha- player >
57+ < ha- icon - but to n @click = ${ playing ? this . pauseOrStop : this . play } .path = ${ playing ? pauseOrStop : mdiPlayCircle } class= "big-icon" > </ ha- icon - but to n >
4058 <ha- icon- butto n hide= ${ noFastForwardAndRewind } @click = ${ this . fastForward } .path = ${ mdiFastForward } > </ ha- icon- butto n>
41- <sonos- ha- player .store = ${ this . store } .features = ${ this . showNext ( ) } > </ sonos- ha- player>
42- <sonos- ha- player .store = ${ this . store } .features = ${ this . showRepeat ( ) } > </ sonos- ha- player>
59+ <ha- icon- butto n hide= ${ noNext } @click = ${ this . next } .path = ${ mdiSkipNext } > </ ha- icon- butto n>
60+ <sonos- repeat hide= ${ noRepeat } .store = ${ this . store } > </ sonos- repeat>
61+
4362 <ha- icon- butto n hide= ${ noUpDown } @click = ${ this . volUp } .path = ${ mdiVolumePlus } > </ ha- icon- butto n>
4463 <div class= "audio-input-format" >
4564 ${ this . config . showAudioInputFormat && until ( this . getAudioInputFormat ( ) ) }
4665 </ div>
47- <sonos - ha- player . store = ${ this . store } .features = ${ this . showBrowseMedia ( ) } > </ sonos - ha- player >
66+ < ha- icon - but to n hide = ${ noBrowse } @click = ${ this . browseMedia } .path = ${ mdiPlayBoxMultiple } > </ ha- icon - but to n >
4867 </ div>
4968 <sonos- volume .store = ${ this . store } .player = ${ this . volumePlayer }
5069 .updateMembers = ${ this . updateMemberVolumes } > </ sonos- volume>
5170 <div class= "icons" >
52- <sonos - ha- player . store = ${ this . store } . features = ${ this . store . showPower ( true ) } > </ sonos - ha- player >
71+ < ha- icon - but to n hide = ${ this . store . hidePower ( true ) } @click = ${ this . togglePower } > </ ha- icon - but to n >
5372 </ div">
5473 </div>
5574 ` ;
5675 }
76+ private prev = async ( ) => await this . mediaControlService . prev ( this . activePlayer ) ;
77+ private play = async ( ) => await this . mediaControlService . play ( this . activePlayer ) ;
78+ private pauseOrStop = async ( ) => {
79+ return this . config . stopInsteadOfPause
80+ ? await this . mediaControlService . stop ( this . activePlayer )
81+ : await this . mediaControlService . pause ( this . activePlayer ) ;
82+ } ;
83+ private next = async ( ) => await this . mediaControlService . next ( this . activePlayer ) ;
84+
85+ private browseMedia = async ( ) => this . mediaBrowseService . showBrowseMedia ( this . activePlayer , this ) ;
86+ private togglePower = async ( ) => await this . mediaControlService . togglePower ( this . activePlayer ) ;
5787
5888 private getVolumePlayer ( ) {
5989 let result ;
@@ -88,26 +118,6 @@ class PlayerControls extends LitElement {
88118 : '' ;
89119 }
90120
91- private showShuffle ( ) {
92- return this . config . hidePlayerControlShuffleButton ? [ ] : [ SHUFFLE_SET ] ;
93- }
94-
95- private showPrev ( ) {
96- return this . config . hidePlayerControlPrevTrackButton ? [ ] : [ PREVIOUS_TRACK ] ;
97- }
98-
99- private showNext ( ) {
100- return this . config . hidePlayerControlNextTrackButton ? [ ] : [ NEXT_TRACK ] ;
101- }
102-
103- private showRepeat ( ) {
104- return this . config . hidePlayerControlRepeatButton ? [ ] : [ REPEAT_SET ] ;
105- }
106-
107- private showBrowseMedia ( ) {
108- return this . config . showBrowseMediaInPlayerSection ? [ BROWSE_MEDIA ] : [ ] ;
109- }
110-
111121 static get styles ( ) {
112122 return css `
113123 .main {
0 commit comments