@@ -29,6 +29,7 @@ import {
2929 CSP_NONCE ,
3030 ChangeDetectorRef ,
3131 AfterViewInit ,
32+ EventEmitter ,
3233} from '@angular/core' ;
3334import { isPlatformBrowser } from '@angular/common' ;
3435import { Observable , of as observableOf , Subject , BehaviorSubject , fromEventPattern } from 'rxjs' ;
@@ -218,22 +219,29 @@ export class YouTubePlayer implements AfterViewInit, OnChanges, OnDestroy {
218219 */
219220 @Input ( ) placeholderImageQuality : PlaceholderImageQuality ;
220221
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.
224224
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. */
225229 @Output ( ) readonly stateChange : Observable < YT . OnStateChangeEvent > =
226230 this . _getLazyEmitter < YT . OnStateChangeEvent > ( 'onStateChange' ) ;
227231
232+ /** Emits when there's an error while initializing the player. */
228233 @Output ( ) readonly error : Observable < YT . OnErrorEvent > =
229234 this . _getLazyEmitter < YT . OnErrorEvent > ( 'onError' ) ;
230235
236+ /** Emits when the underlying API of the player has changed. */
231237 @Output ( ) readonly apiChange : Observable < YT . PlayerEvent > =
232238 this . _getLazyEmitter < YT . PlayerEvent > ( 'onApiChange' ) ;
233239
240+ /** Emits when the playback quality has changed. */
234241 @Output ( ) readonly playbackQualityChange : Observable < YT . OnPlaybackQualityChangeEvent > =
235242 this . _getLazyEmitter < YT . OnPlaybackQualityChangeEvent > ( 'onPlaybackQualityChange' ) ;
236243
244+ /** Emits when the playback rate has changed. */
237245 @Output ( ) readonly playbackRateChange : Observable < YT . OnPlaybackRateChangeEvent > =
238246 this . _getLazyEmitter < YT . OnPlaybackRateChangeEvent > ( 'onPlaybackRateChange' ) ;
239247
@@ -575,7 +583,7 @@ export class YouTubePlayer implements AfterViewInit, OnChanges, OnDestroy {
575583 } ) ,
576584 ) ;
577585
578- const whenReady = ( ) => {
586+ const whenReady = ( event : YT . PlayerEvent ) => {
579587 // Only assign the player once it's ready, otherwise YouTube doesn't expose some APIs.
580588 this . _ngZone . run ( ( ) => {
581589 this . _isLoading = false ;
@@ -584,6 +592,7 @@ export class YouTubePlayer implements AfterViewInit, OnChanges, OnDestroy {
584592 this . _pendingPlayer = undefined ;
585593 player . removeEventListener ( 'onReady' , whenReady ) ;
586594 this . _playerChanges . next ( player ) ;
595+ ( this . ready as EventEmitter < YT . PlayerEvent > ) . emit ( event ) ;
587596 this . _setSize ( ) ;
588597 this . _setQuality ( ) ;
589598
0 commit comments