Skip to content

Commit 5053b5a

Browse files
committed
[YoutubePlayer] Several small updates on the usage of the Youtube API following a breaking change
1 parent 2be30c3 commit 5053b5a

3 files changed

Lines changed: 26 additions & 4 deletions

File tree

administration/static/app/controllers/admin.lesson.controllers.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,14 @@
3232

3333
$scope.play = function(youtube_id) {
3434
youtubePlayerApi.loadPlayer().then(function(player){
35-
if(player.getVideoData().video_id === youtube_id) return;
35+
try {
36+
if(player.getVideoData().video_id === youtube_id) return;
37+
}
38+
catch(err) {
39+
// There has been an error trying to get video data from the player API (provided by Youtube)
40+
// Pass this error silently
41+
}
42+
// Enforce now which video must be played
3643
player.cueVideoById(youtube_id);
3744
});
3845
};

administration/static/js/new-course/controllers.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
$scope.playerReady = false;
4242
youtubePlayerApi.loadPlayer().then(function(p){
4343
player = p;
44+
player.cueVideoById(youtubePlayerApi.videoId);
4445
$scope.playerReady = true;
4546
});
4647

core/static/js/lesson/controllers.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,16 @@
7878
$scope.section = 'video';
7979

8080
youtubePlayerApi.loadPlayer().then(function(player){
81-
if(player.getVideoData() &&
82-
player.getVideoData().video_id === youtube_id) return;
81+
try {
82+
if(player.getVideoData() &&
83+
player.getVideoData().video_id === youtube_id)
84+
return;
85+
}
86+
catch(err) {
87+
// There has been an error trying to get video data from the player API (provided by Youtube)
88+
// Pass this error silently
89+
}
90+
// Enforce now which video must be played
8391
player.cueVideoById(youtube_id);
8492
});
8593
} else {
@@ -315,7 +323,13 @@
315323
var lastState = -1;
316324

317325
function onPlayerStateChange (event) {
318-
var video_id = event.target.getVideoData().video_id;
326+
try {
327+
var video_id = event.target.getVideoData().video_id;
328+
}
329+
catch(err) {
330+
// There has been an error trying to get video data from the player API (provided by Youtube)
331+
// Pass this error silently
332+
}
319333

320334
if (event.data == YT.PlayerState.ENDED){
321335
if(! (lastState === YT.PlayerState.PAUSED || // workaround, YT in html5 mode will fire

0 commit comments

Comments
 (0)