@@ -7,36 +7,21 @@ class PlayerUI {
77 public player : PlayerCore ;
88
99 protected _buttonsBox : HTMLElement ;
10+ protected _volumeSlider : HTMLInputElement ;
11+ protected _loadingProgressBar : HTMLInputElement ;
12+ protected _playingProgressBar : HTMLInputElement ;
1013
1114 constructor ( player : PlayerCore ) {
1215
1316 this . player = player ;
1417
15- this . prepareUI ( ) ;
16-
17- }
18-
19- private prepareUI ( ) {
20-
21- // buttons box
22- this . _buttonsBox = document . getElementById ( 'js-buttons-box' ) ;
18+ this . _prepareUI ( ) ;
2319
2420 }
2521
26- }
27-
28- /*
29-
30- protected _buttonsBox: HTMLElement;
31- protected _volumeSlider: HTMLInputElement;
32- protected _loadingProgressBar: HTMLInputElement;
33- protected _playingProgressBar: HTMLInputElement;
34-
35- constructor(player: PlayerCore) {
36-
37- // compatibility goal: minimum IE11
38-
22+ protected _prepareUI ( ) {
3923
24+ // NOTE TO SELF: compatibility goal: minimum IE11
4025
4126 // buttons box
4227 this . _buttonsBox = document . getElementById ( 'js-buttons-box' ) ;
@@ -53,8 +38,9 @@ class PlayerUI {
5338 // start listening to events
5439 this . _createListeners ( ) ;
5540
56- // set the initial volume volume to the volume input range
41+ // set the initial volume to the volume input range
5742 this . _volumeSlider . value = String ( this . player . getVolume ( ) ) ;
43+ // TODO: use the localstorage or indexeddb to persist the user volume
5844
5945 }
6046
@@ -94,20 +80,18 @@ class PlayerUI {
9480 break ;
9581 }
9682
97- this.switchPlayerContext (playerContext);
83+ this . _switchPlayerContext ( playerContext ) ;
9884
9985 }
10086
10187 if ( $button . id === 'js-previous-button' ) {
10288
103- this.setPlayingProgress (0);
89+ this . _setPlayingProgress ( 0 ) ;
10490
10591 let playerContext = this . _buttonsBox . dataset [ 'playerContext' ] ;
10692
10793 if ( playerContext === 'off' ) {
108-
109- this.switchPlayerContext(playerContext);
110-
94+ this . _switchPlayerContext ( playerContext ) ;
11195 }
11296
11397 this . player . play ( 'previous' ) ;
@@ -116,14 +100,12 @@ class PlayerUI {
116100
117101 if ( $button . id === 'js-next-button' ) {
118102
119- this.setPlayingProgress (0);
103+ this . _setPlayingProgress ( 0 ) ;
120104
121105 let playerContext = this . _buttonsBox . dataset [ 'playerContext' ] ;
122106
123107 if ( playerContext === 'off' ) {
124-
125- this.switchPlayerContext(playerContext);
126-
108+ this . _switchPlayerContext ( playerContext ) ;
127109 }
128110
129111 this . player . play ( 'next' ) ;
@@ -144,7 +126,28 @@ class PlayerUI {
144126
145127 }
146128
147- public switchPlayerContext(currentPlayerContext: string) {
129+ protected _onChangeVolume ( event : Event ) {
130+
131+ // styling the html5 range:
132+ // http://brennaobrien.com/blog/2014/05/style-input-type-range-in-every-browser.html
133+
134+ let rangeElement = event . target as HTMLInputElement ;
135+ let value = parseInt ( rangeElement . value ) ;
136+
137+ this . player . setVolume ( value ) ;
138+
139+ }
140+
141+ protected _onChangePlayingProgress ( event : Event ) {
142+
143+ let rangeElement = event . target as HTMLInputElement ;
144+ let value = parseInt ( rangeElement . value ) ;
145+
146+ this . player . setPosition ( value ) ;
147+
148+ }
149+
150+ protected _switchPlayerContext ( currentPlayerContext : string ) {
148151
149152 let $playIcon = document . getElementById ( 'js-play' ) ;
150153 let $pauseIcon = document . getElementById ( 'js-pause' ) ;
@@ -169,24 +172,33 @@ class PlayerUI {
169172
170173 }
171174
172- protected _onChangeVolume(event: Event ) {
175+ protected _setPlayingProgress ( percentage : number ) {
173176
174- // styling the html5 range:
175- // http://brennaobrien.com/blog/2014/05/style-input-type-range-in-every-browser.html
177+ this . _playingProgressBar . value = percentage . toString ( ) ;
176178
177- let rangeElement = event.target as HTMLInputElement;
178- let value = parseInt(rangeElement.value);
179+ }
179180
180- this.player.setVolume(value);
181+ protected _setLoadingProgress ( percentage : number ) {
182+
183+ this . _loadingProgressBar . value = percentage . toString ( ) ;
181184
182185 }
183186
184- protected _onChangePlayingProgress(event: Event ) {
187+ public changePlayingProgress ( percentage : number ) {
185188
186- let rangeElement = event.target as HTMLInputElement;
187- let value = parseInt(rangeElement.value);
189+ this . _setPlayingProgress ( percentage ) ;
188190
189- this.player.setPosition(value);
191+ }
192+
193+ public changeLoadingProgress ( percentage : number ) {
194+
195+ this . _setLoadingProgress ( percentage ) ;
196+
197+ }
198+
199+ public resetUI ( ) {
200+
201+ this . _switchPlayerContext ( 'on' ) ;
190202
191203 }
192204
@@ -202,24 +214,12 @@ class PlayerUI {
202214
203215 }
204216
205- public setLoadingProgress(percentage: number) {
206-
207- this._loadingProgressBar.value = percentage.toString();
208-
209- }
210-
211- public setPlayingProgress(percentage: number) {
212-
213- this._playingProgressBar.value = percentage.toString();
214-
215- }
216-
217217 public deconstructor ( ) {
218218
219219 this . _destroyListeners ( ) ;
220220
221221 }
222- */
223222
223+ }
224224
225225export { PlayerUI } ;
0 commit comments