@@ -78,7 +78,7 @@ export const DEFAULT_PLAYER_HEIGHT = 390;
78
78
* user tries to interact with the API before it has been loaded.
79
79
*/
80
80
interface PendingPlayerState {
81
- playbackState ?: YT . PlayerState . PLAYING | YT . PlayerState . PAUSED | YT . PlayerState . CUED ;
81
+ playbackState ?: PlayerState . PLAYING | PlayerState . PAUSED | PlayerState . CUED ;
82
82
playbackRate ?: number ;
83
83
volume ?: number ;
84
84
muted ?: boolean ;
@@ -90,6 +90,19 @@ function coerceTime(value: number | undefined): number | undefined {
90
90
return value == null ? value : numberAttribute ( value , 0 ) ;
91
91
}
92
92
93
+ /**
94
+ * Equivalent of `YT.PlayerState` which we can't use, because it's meant to
95
+ * be read off the `window` which we can't do before the API has been loaded.
96
+ */
97
+ enum PlayerState {
98
+ UNSTARTED = - 1 ,
99
+ ENDED = 0 ,
100
+ PLAYING = 1 ,
101
+ PAUSED = 2 ,
102
+ BUFFERING = 3 ,
103
+ CUED = 5 ,
104
+ }
105
+
93
106
/**
94
107
* Angular component that renders a YouTube player via the YouTube player
95
108
* iframe API.
@@ -280,7 +293,8 @@ export class YouTubePlayer implements AfterViewInit, OnChanges, OnDestroy {
280
293
if ( this . _player ) {
281
294
this . _player . playVideo ( ) ;
282
295
} else {
283
- this . _getPendingState ( ) . playbackState = YT . PlayerState . PLAYING ;
296
+ this . _getPendingState ( ) . playbackState = PlayerState . PLAYING ;
297
+ this . _load ( true ) ;
284
298
}
285
299
}
286
300
@@ -289,7 +303,7 @@ export class YouTubePlayer implements AfterViewInit, OnChanges, OnDestroy {
289
303
if ( this . _player ) {
290
304
this . _player . pauseVideo ( ) ;
291
305
} else {
292
- this . _getPendingState ( ) . playbackState = YT . PlayerState . PAUSED ;
306
+ this . _getPendingState ( ) . playbackState = PlayerState . PAUSED ;
293
307
}
294
308
}
295
309
@@ -299,7 +313,7 @@ export class YouTubePlayer implements AfterViewInit, OnChanges, OnDestroy {
299
313
this . _player . stopVideo ( ) ;
300
314
} else {
301
315
// It seems like YouTube sets the player to CUED when it's stopped.
302
- this . _getPendingState ( ) . playbackState = YT . PlayerState . CUED ;
316
+ this . _getPendingState ( ) . playbackState = PlayerState . CUED ;
303
317
}
304
318
}
305
319
@@ -411,7 +425,7 @@ export class YouTubePlayer implements AfterViewInit, OnChanges, OnDestroy {
411
425
return this . _pendingPlayerState . playbackState ;
412
426
}
413
427
414
- return YT . PlayerState . UNSTARTED ;
428
+ return PlayerState . UNSTARTED ;
415
429
}
416
430
417
431
/** See https://developers.google.com/youtube/iframe_api_reference#getCurrentTime */
@@ -581,7 +595,7 @@ export class YouTubePlayer implements AfterViewInit, OnChanges, OnDestroy {
581
595
// Only cue the player when it either hasn't started yet or it's cued,
582
596
// otherwise cuing it can interrupt a player with autoplay enabled.
583
597
const state = player . getPlayerState ( ) ;
584
- if ( state === YT . PlayerState . UNSTARTED || state === YT . PlayerState . CUED || state == null ) {
598
+ if ( state === PlayerState . UNSTARTED || state === PlayerState . CUED || state == null ) {
585
599
this . _cuePlayer ( ) ;
586
600
}
587
601
@@ -598,13 +612,13 @@ export class YouTubePlayer implements AfterViewInit, OnChanges, OnDestroy {
598
612
const { playbackState, playbackRate, volume, muted, seek} = pendingState ;
599
613
600
614
switch ( playbackState ) {
601
- case YT . PlayerState . PLAYING :
615
+ case PlayerState . PLAYING :
602
616
player . playVideo ( ) ;
603
617
break ;
604
- case YT . PlayerState . PAUSED :
618
+ case PlayerState . PAUSED :
605
619
player . pauseVideo ( ) ;
606
620
break ;
607
- case YT . PlayerState . CUED :
621
+ case PlayerState . CUED :
608
622
player . stopVideo ( ) ;
609
623
break ;
610
624
}
0 commit comments