SamirHodzic / ngx-embed-video

Get embed code for embedding youtube/vimeo/dailymotion/* video in websites from URL or ID in Angular 6+.
MIT License
56 stars 41 forks source link

using the youtbe video api #13

Closed Eraldo closed 6 years ago

Eraldo commented 6 years ago

I am wondering how to use enablejsapi to be able to control the player.

I guess this is a feature request: It would be cool to have access to the player api to be able to control it according to the official docs: https://developers.google.com/youtube/iframe_api_reference#Examples

Maybe this is already possible and I just did not understand how. :)

SamirHodzic commented 6 years ago

Currently lib is only processing embedding video part, without real support for JS API (events, etc.). By YT documentation what can be done is setting id and enablejsapi to returned iframe,

this.embedService.embed(`${this.ytUrl}?enablejsapi=1`, attr: { id: 'iframe-example' } })

and then,

function onYouTubeIframeAPIReady() {
  player = new YT.Player('iframe-example', {
      events: {
        'onReady': onPlayerReady
      }
  });
}
function onPlayerReady(event) {
  // do something..
}