@@ -29,6 +29,7 @@ import {
29
29
CSP_NONCE ,
30
30
ChangeDetectorRef ,
31
31
AfterViewInit ,
32
+ EventEmitter ,
32
33
} from '@angular/core' ;
33
34
import { isPlatformBrowser } from '@angular/common' ;
34
35
import { Observable , of as observableOf , Subject , BehaviorSubject , fromEventPattern } from 'rxjs' ;
@@ -218,22 +219,29 @@ export class YouTubePlayer implements AfterViewInit, OnChanges, OnDestroy {
218
219
*/
219
220
@Input ( ) placeholderImageQuality : PlaceholderImageQuality ;
220
221
221
- /** Outputs are direct proxies from the player itself. */
222
- @Output ( ) readonly ready : Observable < YT . PlayerEvent > =
223
- this . _getLazyEmitter < YT . PlayerEvent > ( 'onReady' ) ;
222
+ // Note: ready event can't go through the lazy emitter, because it
223
+ // happens before the `_playerChanges` stream emits the new player.
224
224
225
+ /** Emits when the player is initialized. */
226
+ @Output ( ) readonly ready : Observable < YT . PlayerEvent > = new EventEmitter < YT . PlayerEvent > ( ) ;
227
+
228
+ /** Emits when the state of the player has changed. */
225
229
@Output ( ) readonly stateChange : Observable < YT . OnStateChangeEvent > =
226
230
this . _getLazyEmitter < YT . OnStateChangeEvent > ( 'onStateChange' ) ;
227
231
232
+ /** Emits when there's an error while initializing the player. */
228
233
@Output ( ) readonly error : Observable < YT . OnErrorEvent > =
229
234
this . _getLazyEmitter < YT . OnErrorEvent > ( 'onError' ) ;
230
235
236
+ /** Emits when the underlying API of the player has changed. */
231
237
@Output ( ) readonly apiChange : Observable < YT . PlayerEvent > =
232
238
this . _getLazyEmitter < YT . PlayerEvent > ( 'onApiChange' ) ;
233
239
240
+ /** Emits when the playback quality has changed. */
234
241
@Output ( ) readonly playbackQualityChange : Observable < YT . OnPlaybackQualityChangeEvent > =
235
242
this . _getLazyEmitter < YT . OnPlaybackQualityChangeEvent > ( 'onPlaybackQualityChange' ) ;
236
243
244
+ /** Emits when the playback rate has changed. */
237
245
@Output ( ) readonly playbackRateChange : Observable < YT . OnPlaybackRateChangeEvent > =
238
246
this . _getLazyEmitter < YT . OnPlaybackRateChangeEvent > ( 'onPlaybackRateChange' ) ;
239
247
@@ -575,7 +583,7 @@ export class YouTubePlayer implements AfterViewInit, OnChanges, OnDestroy {
575
583
} ) ,
576
584
) ;
577
585
578
- const whenReady = ( ) => {
586
+ const whenReady = ( event : YT . PlayerEvent ) => {
579
587
// Only assign the player once it's ready, otherwise YouTube doesn't expose some APIs.
580
588
this . _ngZone . run ( ( ) => {
581
589
this . _isLoading = false ;
@@ -584,6 +592,7 @@ export class YouTubePlayer implements AfterViewInit, OnChanges, OnDestroy {
584
592
this . _pendingPlayer = undefined ;
585
593
player . removeEventListener ( 'onReady' , whenReady ) ;
586
594
this . _playerChanges . next ( player ) ;
595
+ ( this . ready as EventEmitter < YT . PlayerEvent > ) . emit ( event ) ;
587
596
this . _setSize ( ) ;
588
597
this . _setQuality ( ) ;
589
598
0 commit comments