@@ -78,6 +78,19 @@ const DEFAULT_PLAYER_HEIGHT = 390;
78
78
function coerceTime ( value ) {
79
79
return value == null ? value : numberAttribute ( value , 0 ) ;
80
80
}
81
+ /**
82
+ * Equivalent of `YT.PlayerState` which we can't use, because it's meant to
83
+ * be read off the `window` which we can't do before the API has been loaded.
84
+ */
85
+ var PlayerState ;
86
+ ( function ( PlayerState ) {
87
+ PlayerState [ PlayerState [ "UNSTARTED" ] = - 1 ] = "UNSTARTED" ;
88
+ PlayerState [ PlayerState [ "ENDED" ] = 0 ] = "ENDED" ;
89
+ PlayerState [ PlayerState [ "PLAYING" ] = 1 ] = "PLAYING" ;
90
+ PlayerState [ PlayerState [ "PAUSED" ] = 2 ] = "PAUSED" ;
91
+ PlayerState [ PlayerState [ "BUFFERING" ] = 3 ] = "BUFFERING" ;
92
+ PlayerState [ PlayerState [ "CUED" ] = 5 ] = "CUED" ;
93
+ } ) ( PlayerState || ( PlayerState = { } ) ) ;
81
94
/**
82
95
* Angular component that renders a YouTube player via the YouTube player
83
96
* iframe API.
@@ -170,7 +183,8 @@ class YouTubePlayer {
170
183
this . _player . playVideo ( ) ;
171
184
}
172
185
else {
173
- this . _getPendingState ( ) . playbackState = YT . PlayerState . PLAYING ;
186
+ this . _getPendingState ( ) . playbackState = PlayerState . PLAYING ;
187
+ this . _load ( true ) ;
174
188
}
175
189
}
176
190
/** See https://developers.google.com/youtube/iframe_api_reference#pauseVideo */
@@ -179,7 +193,7 @@ class YouTubePlayer {
179
193
this . _player . pauseVideo ( ) ;
180
194
}
181
195
else {
182
- this . _getPendingState ( ) . playbackState = YT . PlayerState . PAUSED ;
196
+ this . _getPendingState ( ) . playbackState = PlayerState . PAUSED ;
183
197
}
184
198
}
185
199
/** See https://developers.google.com/youtube/iframe_api_reference#stopVideo */
@@ -189,7 +203,7 @@ class YouTubePlayer {
189
203
}
190
204
else {
191
205
// It seems like YouTube sets the player to CUED when it's stopped.
192
- this . _getPendingState ( ) . playbackState = YT . PlayerState . CUED ;
206
+ this . _getPendingState ( ) . playbackState = PlayerState . CUED ;
193
207
}
194
208
}
195
209
/** See https://developers.google.com/youtube/iframe_api_reference#seekTo */
@@ -286,7 +300,7 @@ class YouTubePlayer {
286
300
if ( this . _pendingPlayerState && this . _pendingPlayerState . playbackState != null ) {
287
301
return this . _pendingPlayerState . playbackState ;
288
302
}
289
- return YT . PlayerState . UNSTARTED ;
303
+ return PlayerState . UNSTARTED ;
290
304
}
291
305
/** See https://developers.google.com/youtube/iframe_api_reference#getCurrentTime */
292
306
getCurrentTime ( ) {
@@ -428,7 +442,7 @@ class YouTubePlayer {
428
442
// Only cue the player when it either hasn't started yet or it's cued,
429
443
// otherwise cuing it can interrupt a player with autoplay enabled.
430
444
const state = player . getPlayerState ( ) ;
431
- if ( state === YT . PlayerState . UNSTARTED || state === YT . PlayerState . CUED || state == null ) {
445
+ if ( state === PlayerState . UNSTARTED || state === PlayerState . CUED || state == null ) {
432
446
this . _cuePlayer ( ) ;
433
447
}
434
448
this . _changeDetectorRef . markForCheck ( ) ;
@@ -441,13 +455,13 @@ class YouTubePlayer {
441
455
_applyPendingPlayerState ( player , pendingState ) {
442
456
const { playbackState, playbackRate, volume, muted, seek } = pendingState ;
443
457
switch ( playbackState ) {
444
- case YT . PlayerState . PLAYING :
458
+ case PlayerState . PLAYING :
445
459
player . playVideo ( ) ;
446
460
break ;
447
- case YT . PlayerState . PAUSED :
461
+ case PlayerState . PAUSED :
448
462
player . pauseVideo ( ) ;
449
463
break ;
450
- case YT . PlayerState . CUED :
464
+ case PlayerState . CUED :
451
465
player . stopVideo ( ) ;
452
466
break ;
453
467
}
0 commit comments