Giter VIP home page Giter VIP logo

Comments (11)

paulirish avatar paulirish commented on August 11, 2024 1

I think this is roughly supported via the jsapi which will be possible to use via #20 (comment)

It'll require some experimentation though.

from lite-youtube-embed.

Garbee avatar Garbee commented on August 11, 2024

Wouldn't you link to the events on the main YouTube video once embedded?

I think we should expose an event when that occurs. Although a MutationObserver could possibly fill the role just fine without us needing to do any extra work. Worth looking into and explaining though.

from lite-youtube-embed.

lborgman avatar lborgman commented on August 11, 2024

I need this so I am implementing it in a fork now. Some thoughts:

  1. "enabjejsapi=1" is needed. How to implement that is trivial. I will use "videoparams=...".
  2. To be of any use the "onYouTubeIframeAPIReady" must be implemented since it sets up the event handlers.
  3. "onYouTubeIframeAPIReady" needs the iframe DOM element.
  4. Since the iframe element is not created until the video is played the "onYouTubeIframeAPIready" must be setup after that.
  5. I am adding a user defined function that will be called to do this - inside "addIframe".

Any thoughts on this?

from lite-youtube-embed.

lborgman avatar lborgman commented on August 11, 2024

So I implemented this. But there is a major obstacle: onYouTubeIframAPIReady
It accepts currently only a single function. That can't work in cases like this. It must accept an array (or something similar).

Is there someone who can reach the developers for that API and tell them this?

from lite-youtube-embed.

Garbee avatar Garbee commented on August 11, 2024

Why won't a single function work? What is the use-case where an array is required to get the expected functionality?

from lite-youtube-embed.

lborgman avatar lborgman commented on August 11, 2024

My use-case is a web component.

from lite-youtube-embed.

lborgman avatar lborgman commented on August 11, 2024

Eh, sorry, my bad. It works fine with a single function.

from lite-youtube-embed.

Garbee avatar Garbee commented on August 11, 2024

My use-case is a web component.

That's not a use-case, that's just what you're trying to use it in. A use case defines what your goal is, how you're approaching the problem, and what about the external API isn't allowing you to move forward.

Eh, sorry, my bad. It works fine with a single function.

So there is no need to try and get an array to be supported by the YouTube API?

from lite-youtube-embed.

lborgman avatar lborgman commented on August 11, 2024

So there is no need to try and get an array to be supported by the YouTube API?

No, it was my mistake. (As I guess anyone here realize you just wrap the old function in onYouTubeIframAPIReady in your new function.)

from lite-youtube-embed.

lborgman avatar lborgman commented on August 11, 2024

Something like this for wrapping:

`

(() => {
    function myOnLoaded() {
        console.warn("myOnloaded dispatch gotapi")
        window.dispatchEvent(new Event("my-gotapi"));
    }
    async function startLoading() {
        const tag = document.createElement('script');
        tag.src = 'https://www.youtube.com/iframe_api';
        await new Promise(function (resolve) {
            if (document.readyState !== "loading") return resolve();
            document.addEventListener("DOMContentLoaded", resolve);
        });
        document.body.append(tag);
    }
    if (window["YT"]) {
        myOnLoaded();
        return;
    }
    if (!window["onYouTubeIframeAPIReady"]) {
        window["onYouTubeIframeAPIReady"] = myOnLoaded;
    } else {
        const theirOnLoaded = window["onYouTubeIframeAPIReady"];
        window["onYouTubeIframeAPIReady"] = () => {
            theirOnLoaded();
            myOnLoaded();
        }
    }
    startLoading();
})();

`

from lite-youtube-embed.

paulirish avatar paulirish commented on August 11, 2024

as of 0.1.0, you can now easily turn on the js api: https://github.com/paulirish/lite-youtube-embed#custom-player-parameters

with enablejsapi=1 ... you can then use https://developers.google.com/youtube/iframe_api_reference

from lite-youtube-embed.

Related Issues (20)

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.