Do not destroy and create new player on video change.
Fix for https://github.com/brandly/angular-youtube-embed/issues/46. Instead of creating a new player, use the current one when it's already existing, loading the new video via YT method loadVideoById
I have experienced this same problem. I didn't know what scope.player.d was, but I didn't want to remove that code in case it was doing something. So I decided that when the player was created I would fill it with something that would allow the check to destroy it in the even that it never gets overwritten or filled with something else.
I added this:
// I don't know why, but in some cases player.d is missing. // It is needed in case it needs to be destroyed. //So if it is not there, then I just arbitrarily set it to true. if (player.d) { console.log("YouTube player.d exists in this object: "); console.log(player); } else { player.d = true; }
x Jeremy M.
Directive portion in the function: createPlayer fix for this where I added:
function createPlayer () { var playerVars = angular.copy(scope.playerVars); playerVars.start = playerVars.start || scope.urlStartTime; var player = new YT.Player(playerId, { height: scope.playerHeight, width: scope.playerWidth, videoId: scope.videoId, playerVars: playerVars, events: { onReady: onPlayerReady, onStateChange: onPlayerStateChange } }); player.id = playerId; // I don't know why, but in some cases player.d is missing. // It is needed in case it needs to be destroyed. //So if it is not there, then I just arbitrarily set it to true. if (player.d) { console.log("YouTube player.d exists in this object: "); console.log(player); } else { player.d = true; } return player; }
P.S. - I am sorry is this is a newbie way to respond, but I just signed into git hub in order to post this, and so I am indeed a newbie. Hope this helps.