Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(youtube-player): handle API interactions before API has loaded #18368

Merged

Conversation

crisbeto
Copy link
Member

@crisbeto crisbeto commented Feb 2, 2020

Currently if the user tries to interact with the API before the YouTube API has loaded (e.g. by calling playVideo) their method call will be ignored. These changes add some logic that will store the state and replay it once the player has been initialized.

Fixes #18279.

Currently if the user tries to interact with the API before the YouTube API has loaded (e.g. by calling `playVideo`) their method call will be ignored. These changes add some logic that will store the state and replay it once the player has been initialized.

Fixes angular#18279.
@crisbeto crisbeto added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent target: patch This PR is targeted for the next patch release labels Feb 2, 2020
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Feb 2, 2020
@mcroker
Copy link

mcroker commented Feb 3, 2020

@crisbeto - thank-you for jumping in and helping with this issue...
...the PR doesn't quite solve the issue for me - specifically I was calling player.getDuration() on the ready event which is don't think you've addressed

Your PR did however give me insight into what was going on. Is there any reason we wouldn't just move the ready event to be triggered by the playerObs?

    // Set up side effects to bind inputs to the player.
    playerObs.subscribe(player => {
      this._player = player
      this.ready.emit({} as YT.PlayerEvent);
    });

and of course remove the current trigger for ready...

    const events = new Map<keyof YT.Events, EventEmitter<any>>([
      ['onReady', this.notTheCurrentReadyEvent],
...
    ]);

@crisbeto
Copy link
Member Author

crisbeto commented Feb 3, 2020

I'm not the one that set up the component initially so I don't have all the context, but I think that it's written this way, because we bind to the onReady event from the YouTube API, rather than emit when we think that the player is ready. These two could be emitted at different times (e.g. if we create the player, but have to wait a while for it to become ready).

@mcroker
Copy link

mcroker commented Feb 3, 2020

From the point of view of a external component, I consider the component to be ready when I can interact with the player... I can see it's coming from the iFrame player, but I'm not entirely sure what the current ready event gives me as I can't yet interact with the player.

Perhaps two events would be the right solution? onIFramePlayerReadyEvent, and onReady?

Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jelbourn jelbourn added pr: lgtm action: merge The PR is ready for merge by the caretaker labels Feb 4, 2020
@mmalerba mmalerba merged commit 0d108d3 into angular:master Feb 4, 2020
mmalerba pushed a commit that referenced this pull request Feb 5, 2020
…18368)

Currently if the user tries to interact with the API before the YouTube API has loaded (e.g. by calling `playVideo`) their method call will be ignored. These changes add some logic that will store the state and replay it once the player has been initialized.

Fixes #18279.
yifange pushed a commit to yifange/components that referenced this pull request Feb 6, 2020
…ngular#18368)

Currently if the user tries to interact with the API before the YouTube API has loaded (e.g. by calling `playVideo`) their method call will be ignored. These changes add some logic that will store the state and replay it once the player has been initialized.

Fixes angular#18279.
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Mar 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

youtube-player Unable to play video in ready Event handler.
5 participants