@superherocheesecake/youtube-manager

3.0.4 • Public • Published

YoutubeManager

Small helper that will load the Youtube script the moment you need it. Your application will initially load faster, because you don't have to wait for this third party API to finish loading.

NPM installation

npm i --save @superherocheesecake/youtube-manager

Load

import YoutubeManager from '@superherocheesecake/youtube-manager';

const youtubeManager = new YoutubeManager();
youtubeManager.addEventListenerOnce('ready', this._youtubeReadyHandler);
youtubeManager.load();

Youtube API Usage

_youtubeReadyHandler: function() {
    this.player = new YT.Player('[#ID]', {
        videoId: [YOUTUBE ID],
        playerVars: {autoplay: 1, showinfo: 0},
        width: [WIDTH],
        height: [HEIGHT],
    });
    this.player.addEventListener('onStateChange', this._onStateChangeHandler);
},

_onStateChangeHandler: function(e) {
    switch(e.data) {
        case YT.PlayerState.ENDED:
            console.log('ended');
            break;
        case YT.PlayerState.PLAYING:
            console.log('playing');
            break;
        case YT.PlayerState.PAUSED:
            console.log('paused');
            break;
        case YT.PlayerState.BUFFERING:
            console.log('buffering');
            break;
        case YT.PlayerState.CUED:
            console.log('cued');
            break;
    }
}

Readme

Keywords

none

Package Sidebar

Install

npm i @superherocheesecake/youtube-manager

Weekly Downloads

0

Version

3.0.4

License

none

Unpacked Size

9.64 kB

Total Files

12

Last publish

Collaborators

  • n0cha
  • edwardmediamonks
  • wesleysmulders
  • ksawery.mediamonks
  • vandenhork25
  • johanholwerda
  • renedrie
  • kristemmerman123
  • odin.schwartz
  • bolex222
  • coco_g
  • frontend_shcc
  • carinashcc
  • lukasfeitsma
  • jameswhite
  • raul.roman
  • jaak.kivinukk