itsahappymedium / meteor-youtube-iframe-api

Youtube Iframe API Meteor package

Home Page:https://atmospherejs.com/adrianliaw/youtube-iframe-api

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Meteor YouTube Iframe API

YouTube Iframe API for Meteor

Basic Usage:

Add package to project.

cd [your_meteor_project]/packages
git clone git@github.com:itsahappymedium/meteor-youtube-iframe-api.git
meteor add itsahappymedium:youtube-iframe-api

Some HTML Setups, you need to create a div with an id.

<body>
    <div id="player"></div>
</body>

In JavaScript, you can include a video like this.

// Make sure it's in client
if (Meteor.isClient) {

    // YouTube API will call onYouTubeIframeAPIReady() when API ready.
    // Make sure it's a global variable.
    onYouTubeIframeAPIReady = function () {

        // New Video Player, the first argument is the id of the div.
        // Make sure it's a global variable.
        player = new YT.Player("player", {

            height: "400",
            width: "600",

            // videoId is the "v" in URL (ex: http://www.youtube.com/watch?v=LdH1hSWGFGU, videoId = "LdH1hSWGFGU")
            videoId: "LdH1hSWGFGU",

            // Events like ready, state change,
            events: {

                onReady: function (event) {

                    // Play video when player ready.
                    event.target.playVideo();
                }

            }

        });

    };

    YT.load();
}

For full documentation of YouTube Iframe API, see Google Developers

About

Youtube Iframe API Meteor package

https://atmospherejs.com/adrianliaw/youtube-iframe-api

License:MIT License


Languages

Language:JavaScript 100.0%