Code Monkey home page Code Monkey logo

youtubeiframeplayer-externs's Introduction

Youtube IFrame Player API externs for Haxe

Overview

This is extern for Haxe. A tool for controlling Youtube with Javascript for everyone.

Original API document: https://developers.google.com/youtube/iframe_api_reference

Example

If you use Youtube.init, loading Youtube IFrame Player API with HTML is unnecessary.

Please refer to the following haxe code or example directory.

HTML code.

<div id="video" data-video-id="M7lc1UVf-VE"></div>

Haxe code:

import js.Browser;
import js.html.Element;
import js.youtube.Youtube;
import js.youtube.YoutubePlayer;

class Main {

    public static function main():Void {

        Browser.window.addEventListener('DOMContentLoaded',function() {

            Youtube.init(onAPIReady);

        });

    }

    private static function onAPIReady():Void {

        var target:Element = Browser.document.getElementById('video');
        var player:YoutubePlayer = new YoutubePlayer(target.id,{
            videoId:target.dataset.videoId,
            events: {
                onReady:function(event:ReadyEvent) {
                }
            }
        });

    }

}

Generate JavaScript code:

// Generated by Haxe 3.4.7
(function () { "use strict";
var Main = function() { };
Main.main = function() {
    window.addEventListener("DOMContentLoaded",function() {
        js_youtube_Youtube.init(Main.onAPIReady);
    });
};
Main.onAPIReady = function() {
    var target = window.document.getElementById("video");
    var player = new YT.Player(target.id,{ videoId : target.dataset.videoId, events : { onReady : function(event) {
    }}});
};
var js_youtube_Youtube = function() { };
js_youtube_Youtube.init = function(onAPIReady) {
    var firstElement = window.document.getElementsByTagName("script")[0];
    var script = window.document.createElement("script");
    script.src = "https://www.youtube.com/player_api";
    firstElement.parentNode.insertBefore(script,firstElement);
    window.onYouTubePlayerAPIReady = function() {
        js_youtube_Youtube.isLoadedAPI = true;
        if(onAPIReady != null) {
            onAPIReady();
        }
    };
};
js_youtube_Youtube.isLoadedAPI = false;
js_youtube_Youtube.API_URL = "https://www.youtube.com/player_api";
Main.main();
})();

References

Original API document: https://developers.google.com/youtube/iframe_api_reference

youtubeiframeplayer-externs's People

Contributors

okawa-h avatar rblsb avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

rblsb

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.