0

I have a certain scenario in my plugin which requires me to change location of youtube player.

I have noticed that when I change the parent which holds youtube player that the youtube api gets initialized again. Is this expected behavior and can this be prevent somehow so the player keeps original api while changing parent?

(this also happens if you set css diplay none on the player!)

I have made a simplified demo here, scroll down click on reparent once video starts playing. You can see in console that player api is created again.

I have an example here: https://jsfiddle.net/kx4cnjt0/6/

<div id="holder"></div>
<div id="holder2"></div>
<a id="rp" href="#">reparent</a>
Toniq
  • 4,492
  • 12
  • 50
  • 109
  • Why move a player? DOM manipulation can get heavy on resources. Why not have 2 players and just pause the first player: save the `currentTime` (or YT API equivalent), `display:none`. On second player: `display:block`, get the `currentTime`, and play. – zer00ne Dec 08 '16 at 23:45
  • I have explained my plugin structure requires changing player location in different parent. 2 players will not solve anything. I could only hack this by having one player and calculate math to position on the same place to look like it was placed in parent containers (whose position changes on the page) – Toniq Dec 08 '16 at 23:51
  • 2 different parents doesn't matter, neither does it matter of what position said players are or going to be, or have been, or never have been. The div is replaced by an iframe, so you are not moving a div you are moving an iframe. It will always reset read [this](http://stackoverflow.com/a/8318401/2813224) – zer00ne Dec 09 '16 at 00:23
  • Yes, but youtube api also resets if you set css display none on div which holds the player (and then display block later). – Toniq Dec 09 '16 at 01:10
  • The div that *"holds"* player is replaced by an iframe. Those divs are just placeholders. – zer00ne Dec 09 '16 at 01:39
  • I understand that, but I can wrap another div around placeholder div, the result is the same. – Toniq Dec 09 '16 at 02:00
  • When you put `display:none` on the div that wraps the iframe or move it, it'll affect all elements nested within as well – zer00ne Dec 09 '16 at 02:28

0 Answers0