1

I'm currently using the @angular/youtube-player package for Angular 12. I'm using the <youtube-player> tag the library suggests as follows:

<youtube-player *ngIf="currentMedia === 'youtube'" videoId="{{currentVid}}" suggestedQuality="highres" [height]="250" [width]="500" ></youtube-player>

I have the iframe API in index.html as some tutorial video suggested and it seems to work for making the video initialize.

The question is, how do I call the API? For example, I want to do something like player.getCurrentTime() or change the time around with javascript. Does anyone know? I haven't found any good documentation for it with the angular youtube-player.

1 Answer 1

1

All the API method are implemented in the component itself. Check the code here.

github code

You can create a component instance in the constructor, or even using # reference in the HTML to call those methods.

.html

<youtube-player *ngIf="currentMedia === 'youtube'" videoId="{{currentVid}}" suggestedQuality="highres" [height]="250" [width]="500" #player></youtube-player>

.ts

@ViewChild('player') child_component: YouTubePlayer;

someMethod(){
  this.child_component.getCurrentTime(); // Or any public method
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the response. Where exactly is YouTubePlayer coming from for the child component? I'm getting an error of Cannot find name 'YouTubePlayer'. 14 @ViewChild('player') player: YouTubePlayer;
Thats the type of the component, you can import , you might have imported in the module to use that in html ? same way you can import here just to add a type to var.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.