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

feat(YOUTUBE PLAYER): Expose private _player object #30643

Open
mattiLeBlanc opened this issue Mar 18, 2025 · 3 comments
Open

feat(YOUTUBE PLAYER): Expose private _player object #30643

mattiLeBlanc opened this issue Mar 18, 2025 · 3 comments
Labels
feature This issue represents a new feature or feature request rather than a bug or bug fix needs triage This issue needs to be triaged by the team

Comments

@mattiLeBlanc
Copy link

Feature Description

Please expose the private _player object because we can use that to access things like getPlaylist() or getVideoData which comes in handy.

Use Case

I want to control the youtube playlist myself and not use the build in controls in the iframe due to usability issue on TV.
Therefor, i can get official access to the _player I can get the playlists ids and load a next video or tell the player to execute nextVideo.

@mattiLeBlanc mattiLeBlanc added feature This issue represents a new feature or feature request rather than a bug or bug fix needs triage This issue needs to be triaged by the team labels Mar 18, 2025
@crisbeto
Copy link
Member

I think it's valid, but the problem is that the player isn't necessarily always available. E.g. we haven't initialized it when showing the placeholder or if you try to read it while the API is loading.

@mattiLeBlanc
Copy link
Author

@crisbeto I understand.
The only way I can use it now is to reference and put // @ts-ignore above it. Which is not great.
Maybe you can make it available with a side note that is may be undefined in certain cases.
I would be using it when a video or playlist is loaded.

@mattiLeBlanc
Copy link
Author

mattiLeBlanc commented Mar 19, 2025

@crisbeto actually I found another way which may work (and could be documented)

onReady(event: YT.PlayerEvent) {
    console.log('event', event.target.getPlaylist())
}

html:

<youtube-player
      [videoId]="source.reference"
      [height]="height()"
      [width]="width()"
      (stateChange)="stateChange($event)"
      (ready)="onReady($event)"
      ....

I can now use the event.target which is Player reference and it is fully typed. So that works for me as a workaround for now.
But It would be great if the player becomes public, so I can execute player.nextVideo or previousVideo.

Strangely this event doesn't fire if you only load 1 video instead of a playlist. I guess that is an implementation inconsistence in this library?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature This issue represents a new feature or feature request rather than a bug or bug fix needs triage This issue needs to be triaged by the team
Projects
None yet
Development

No branches or pull requests

2 participants