Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

179
Views
Using addPlayer instead of window

Is this YouTube code able to use addPlayer instead of window?

I was trying to figure out how to do that.

Does window have to be used with loadPlayer()?

Working code using window, trying to use addPlayer instead with loadPlayer().

https://jsfiddle.net/xdrtuj5e/

   const videoPlayer = (function makeVideoPlayer() {
    
      let player = null;
    
      function loadPlayer() {
        const tag = document.createElement("script");
        tag.src = "https://www.youtube.com/iframe_api";
        const firstScriptTag = document.getElementsByTagName("script")[0];
        firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
      }
    
      function onPlayerReady(event) {
        player = event.target;
        player.setVolume(100);
      }
    
      window.onYouTubePlayerAPIReady = function() {
    
        const video = document.querySelector(".video");
    
        /* function addPlayer(video) { */
    
        new YT.Player(video, {
          width: 606,
          height: 344,
          videoId: video.dataset.id,
          playerVars: {
            autoplay: 0,
            controls: 1,
            showinfo: 1,
            rel: 0,
            iv_load_policy: 3,
            cc_load_policy: 0,
            fs: 0,
            disablekb: 1
          },
          events: {
            "onReady": onPlayerReady
          }
        });
      };
    
      function init() {
        loadPlayer();
      }
      return {
        /* addPlayer,*/
        init
      };
    
    }());
    
    
    (function iife() {
    
      function coverClickHandler(evt) {
        videoPlayer.init();
      }
    
      const cover = document.querySelector(".playa");
      cover.addEventListener("click", coverClickHandler);
    }());
    
    
    /*
    function onYouTubeIframeAPIReady() {
      const frameContainer = document.querySelector(".video");
      videoPlayer.addPlayer(frameContainer);
    }*/
    
   /* 
    function onYouTubeIframeAPIReady() {
      const cover = document.querySelector(".playa");
      const wrapper = cover.parentElement;
      const frameContainer = wrapper.querySelector(".video");
      videoPlayer.addPlayer(frameContainer);
    }*/
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!