Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3831

YT.Player doesn't return an instance with playVideo()

$
0
0

When I create an instance of YT.Player(HTMLIFrameElement, { options }) I get back an object that has:

  • destroy
  • setSize
  • getIframe
  • addEventListener
  • getVideoEmbedCode
  • getOptions
  • getOption

But not playVideo, pauseVideo etc as described in the documentation.

I got a demo here: http://siesta-annotations.surge.sh/Siesta_webviewer_test/?page=3

I am creating the iframes via the DOM in trait.playable.youtube.js and adding the iframe to a documentFragment that eventually will be added to a div:

const element = document.createElement('iframe')element.src = `https://www.youtube.com/embed/${id}?rel=0;&autoplay=${this.options.autostart ? 1 : 0};&enablejsapi=1;&origin=${location.hostname};`element.style = this.inlineStyle

I then create an instance of YT.Player:

// nasty initialization because we're outside webpack and this is a demoif (global.YT.loaded) {  this.player = new global.YT.Player(element, {    events: {'onStateChange': this.stateHandler,'onReady': onPlayerReady    }  })} else {  const oldHandler = global.onYouTubeIframeAPIReady  global.onYouTubeIframeAPIReady = () => {    if (oldHandler) oldHandler()    this.player = new global.YT.Player(element, {      events: {'onStateChange': this.stateHandler,'onReady': onPlayerReady      }    })  }}

The instance of YT.Player looks something like this:

YT.Player instance object tree

It looks like the minification process went very wrong. What am I doing wrong - how should I initialise YT.Player for my use-case?


Viewing all articles
Browse latest Browse all 3831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>