From 7a76335a5f4fc8f5aaa11b5148ac38434080ff1a Mon Sep 17 00:00:00 2001 From: Miguel Martinez Date: Sun, 26 Feb 2017 00:20:44 +0100 Subject: [PATCH 1/2] Fixes #84, Avoids destroying old player when loading new video --- src/angular-youtube-embed.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/angular-youtube-embed.js b/src/angular-youtube-embed.js index cb7592d..7189023 100644 --- a/src/angular-youtube-embed.js +++ b/src/angular-youtube-embed.js @@ -192,11 +192,12 @@ angular.module('youtube-embed', []) function loadPlayer () { if (scope.videoId || scope.playerVars.list) { - if (scope.player && typeof scope.player.destroy === 'function') { - scope.player.destroy(); + if (scope.player) { + // player already exists do not replace instead use old player + scope.player.loadVideoById(scope.videoId, 0, 'default'); + } else { + scope.player = createPlayer(); } - - scope.player = createPlayer(); } }; From 14d920aaa00a3614a5cb9744b26e8b1361c3a6b9 Mon Sep 17 00:00:00 2001 From: Miguel Martinez Date: Sun, 26 Feb 2017 02:06:30 +0100 Subject: [PATCH 2/2] Added support for reusing player for playlist, and included demo --- src/angular-youtube-embed.js | 5 ++++- src/demo/advanced.html | 10 ++++++++++ src/demo/the.js | 15 +++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/angular-youtube-embed.js b/src/angular-youtube-embed.js index 7189023..0587570 100644 --- a/src/angular-youtube-embed.js +++ b/src/angular-youtube-embed.js @@ -194,7 +194,10 @@ angular.module('youtube-embed', []) if (scope.videoId || scope.playerVars.list) { if (scope.player) { // player already exists do not replace instead use old player - scope.player.loadVideoById(scope.videoId, 0, 'default'); + if(scope.playerVars.list) + scope.player.loadPlaylist({ list: scope.playerVars.list, index: 0, suggestedQuality: "default"}); + else + scope.player.loadVideoById(scope.videoId, 0, 'default'); } else { scope.player = createPlayer(); } diff --git a/src/demo/advanced.html b/src/demo/advanced.html index e4a4a41..a5b38a4 100644 --- a/src/demo/advanced.html +++ b/src/demo/advanced.html @@ -44,6 +44,16 @@

playlist

+
+

dynamic playlist id

+
+ +
+
+ +
+
+

dynamic video id

diff --git a/src/demo/the.js b/src/demo/the.js index ea8baf6..e1f5002 100644 --- a/src/demo/the.js +++ b/src/demo/the.js @@ -70,6 +70,21 @@ myApp.controller('AdvancedCtrl', function ($scope) { } }; + var firstPlaylist = 'PLISo53ifQd_iBPpybJay-SCAULHsoRicc'; + var secondPlaylist = 'PLfKJ52Aom315E9RXmLkXeD3yS7rsIAgpQ' + $scope.dynamicPlaylist = { + vars: { + list: firstPlaylist + }, + change: function () { + if ($scope.dynamicPlaylist.vars.list === firstPlaylist) { + $scope.dynamicPlaylist.vars.list = secondPlaylist; + } else { + $scope.dynamicPlaylist.vars.list = firstPlaylist; + } + } + }; + var first = 'biZLZZFb468'; var second = 'lbVdyPZiOLM'; $scope.dynamic = {