@@ -4,6 +4,12 @@ import type { WithNormalizedProps } from "../../global";
44import { getElements } from "./elements" ;
55const DEFAULT_SPINNER_TIMEOUT = 2000 ;
66
7+ declare global {
8+ interface Window {
9+ shaka : any ;
10+ }
11+ }
12+
713const eventList = [
814 "abort" ,
915 "canplay" ,
@@ -29,14 +35,14 @@ const videoConfig = {
2935 addSeekBar : true ,
3036 controlPanelElements : [
3137 "play_pause" ,
32- "time_and_duration " ,
38+ "current_time " ,
3339 "spacer" ,
34- "mute" ,
40+ "total_time" ,
41+ "captions" ,
42+ "mute_popover" ,
3543 "report" ,
36- "fullscreen" ,
37- "overflow_menu" ,
44+ "fullscreen_button" ,
3845 ] ,
39- overflowMenuButtons : [ "captions" ] ,
4046} ;
4147
4248export interface PlayPauseEvent {
@@ -57,7 +63,15 @@ interface VideoInput extends Omit<Marko.HTML.Video, `on${string}`> {
5763 "volume-slider" ?: boolean ;
5864 clip ?: any [ ] ;
5965 source : Marko . AttrTag < Marko . HTML . Source > ;
66+ /**
67+ * @deprecated Use `a11y-report-text` instead
68+ */
6069 "report-text" ?: AttrString ;
70+ "a11y-report-text" ?: AttrString ;
71+ "a11y-mute-text" ?: AttrString ;
72+ "a11y-unmute-text" ?: AttrString ;
73+ "a11y-fullscreen-text" ?: AttrString ;
74+ "a11y-exit-fullscreen-text" ?: AttrString ;
6175 "spinner-timeout" ?: number ;
6276 thumbnail ?: string ;
6377 track ?: Marko . AttrTag < Marko . HTML . Track > ;
@@ -79,7 +93,6 @@ interface State {
7993 isLoaded : boolean ;
8094 volumeSlider : boolean ;
8195 action : "play" | "pause" | "" ;
82- showLoading : boolean ;
8396}
8497
8598class Video extends Marko . Component < Input , State > {
@@ -108,6 +121,24 @@ class Video extends Marko.Component<Input, State> {
108121 if ( ! this . input . width && this . video ) {
109122 const { width : containerWidth } = this . root . getBoundingClientRect ( ) ;
110123 this . containerEl . setAttribute ( "width" , containerWidth . toString ( ) ) ;
124+ this . alignSeekbar ( ) ;
125+ }
126+ }
127+
128+ alignSeekbar ( ) {
129+ if ( this . el ) {
130+ const buttonPanel = this . el . querySelector < HTMLElement > (
131+ ".shaka-controls-button-panel" ,
132+ ) ! ;
133+ const spacer = buttonPanel . querySelector ( ".shaka-spacer" ) ! ;
134+ const rangeContainer = this . el . querySelector < HTMLElement > (
135+ ".shaka-range-container" ,
136+ ) ! ;
137+ const buttonPanelRect = buttonPanel . getBoundingClientRect ( ) ;
138+ const spacerRect = spacer . getBoundingClientRect ( ) ;
139+
140+ rangeContainer . style . marginRight = `${ buttonPanelRect . right - spacerRect . right } px` ;
141+ rangeContainer . style . marginLeft = `${ spacerRect . left - buttonPanelRect . left } px` ;
111142 }
112143 }
113144
@@ -117,10 +148,12 @@ class Video extends Marko.Component<Input, State> {
117148 this . video . controls = false ;
118149
119150 this . emit ( "pause" , { originalEvent, player : this . player } ) ;
151+ this . alignSeekbar ( ) ;
120152 }
121153
122154 handlePlaying ( originalEvent : Event ) {
123155 this . showControls ( ) ;
156+ this . alignSeekbar ( ) ;
124157
125158 if ( this . input . playView === "fullscreen" ) {
126159 this . video . requestFullscreen ( ) ;
@@ -197,7 +230,6 @@ class Video extends Marko.Component<Input, State> {
197230 this . state = {
198231 volumeSlider : false ,
199232 action : "" ,
200- showLoading : false ,
201233 isLoaded : true ,
202234 failed : false ,
203235 played : false ,
@@ -248,7 +280,14 @@ class Video extends Marko.Component<Input, State> {
248280 }
249281
250282 _attach ( ) {
251- const { Report, TextSelection } = getElements ( this ) ;
283+ const {
284+ Report,
285+ CurrentTime,
286+ TotalTime,
287+ MuteButton,
288+ FullscreenButton,
289+ TextSelection,
290+ } = getElements ( this ) ;
252291 // eslint-disable-next-line no-undef,new-cap
253292 this . ui = new this . shaka . ui . Overlay (
254293 this . player ,
@@ -263,10 +302,31 @@ class Video extends Marko.Component<Input, State> {
263302 . changeLocale ( [ document . documentElement . lang ] ) ;
264303 }
265304
305+ // eslint-disable-next-line no-undef,new-cap
306+ this . shaka . ui . Controls . registerElement ( "report" , new Report . Factory ( ) ) ;
307+
308+ // eslint-disable-next-line no-undef,new-cap
309+ this . shaka . ui . Controls . registerElement (
310+ "current_time" ,
311+ new CurrentTime . Factory ( ) ,
312+ ) ;
313+
314+ // eslint-disable-next-line no-undef,new-cap
315+ this . shaka . ui . Controls . registerElement (
316+ "total_time" ,
317+ new TotalTime . Factory ( ) ,
318+ ) ;
319+
320+ // eslint-disable-next-line no-undef,new-cap
321+ this . shaka . ui . Controls . registerElement (
322+ "mute_popover" ,
323+ new MuteButton . Factory ( ) ,
324+ ) ;
325+
266326 // eslint-disable-next-line no-undef,new-cap
267327 this . shaka . ui . Controls . registerElement (
268- "report " ,
269- new Report . Factory ( this . input . reportText ) ,
328+ "fullscreen_button " ,
329+ new FullscreenButton . Factory ( ) ,
270330 ) ;
271331
272332 // eslint-disable-next-line no-undef,new-cap
@@ -317,7 +377,7 @@ class Video extends Marko.Component<Input, State> {
317377 this . video = this . root . querySelector ( "video" ) ! ;
318378 this . containerEl = this . root . querySelector ( ".video-player__container" ) ! ;
319379 this . video . volume = this . input . volume || 1 ;
320- this . video . muted = this . input . muted || false ;
380+ this . video . muted = this . input . muted !== false ;
321381
322382 this . subscribeTo ( this . video )
323383 . on ( "playing" , this . handlePlaying . bind ( this ) )
@@ -345,10 +405,12 @@ class Video extends Marko.Component<Input, State> {
345405 shakaLoad ( )
346406 . then ( ( shaka : any ) => {
347407 this . shaka = shaka . default || shaka ;
408+ window . shaka = this . shaka ; // Set global object for some components to access
348409
349410 this . handleSuccess ( ) ;
350411 } )
351412 . catch ( ( e : Error ) => {
413+ console . log ( e ) ;
352414 this . handleError ( e ) ;
353415 } ) ;
354416 }
0 commit comments