From 05ce1a0eb55fcd61130776d4aa7629370579d788 Mon Sep 17 00:00:00 2001 From: Ernie Park Date: Tue, 10 Jan 2012 16:03:41 -0500 Subject: [PATCH 1/3] HTML5 fallback working, time duration buggy from earlier, loading different tabs subtitles/autoplay isn't triggered --- js/video_player.js | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/js/video_player.js b/js/video_player.js index f91bc68482..e86b8ddef7 100644 --- a/js/video_player.js +++ b/js/video_player.js @@ -152,9 +152,32 @@ function onYouTubePlayerReady(playerId) { var id=load_id; loadNewVideo(id, 0); } - } +/* HTML5 YouTube iFrame API Specific */ +function onYouTubePlayerAPIReady() { + ytplayer = new YT.Player('html5_player', { + events: { + 'onReady': onPlayerReady, + 'onStateChange': onPlayerStateChange + } + }); + updateytplayerInfoInterval = setInterval(updateytplayerInfo, 500); + ajax_videoInterval = setInterval(ajax_video, 5000); +} + +function onPlayerReady(event) { + // alert("ready"); + event.target.playVideo(); +} + +function onPlayerStateChange(event) { + if (event.data == YT.PlayerState.PLAYING) { + } +} + +/* End HTML5 Specific */ + // clear pings to video status when we switch to a different sequence tab with ajax function videoDestroy() { load_id = 0; @@ -233,7 +256,7 @@ function updateytplayerInfo() { update_captions(getCurrentTime()); } - // updateHTML("videoduration", getDuration()); + // updateHTML("videoduration", getDuration()); // updateHTML("videotime", getCurrentTime()); // updateHTML("startbytes", getStartBytes()); // updateHTML("volume", getVolume()); From ec86424b41acfb056f702b1322d227ac934283f2 Mon Sep 17 00:00:00 2001 From: Ernie Park Date: Tue, 10 Jan 2012 16:05:45 -0500 Subject: [PATCH 2/3] fix video duration bug: when formatting time use floor, not round --- js/video_player.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/js/video_player.js b/js/video_player.js index e86b8ddef7..c4185e8a5f 100644 --- a/js/video_player.js +++ b/js/video_player.js @@ -102,9 +102,9 @@ function caption_index(now) { function format_time(t) { - seconds = Math.round(t); - minutes = Math.round(seconds / 60); - hours = Math.round(minutes / 60); + seconds = Math.floor(t); + minutes = Math.floor(seconds / 60); + hours = Math.floor(minutes / 60); seconds = seconds % 60; minutes = minutes % 60; return hours+":"+((minutes < 10)?"0":"")+minutes+":"+((seconds < 10)?"0":"")+(seconds%60); From b7974ad27ba7619c5d0873424a3ba9201ecc7cb8 Mon Sep 17 00:00:00 2001 From: Ernie Park Date: Wed, 11 Jan 2012 16:03:34 -0500 Subject: [PATCH 3/3] fix bug where HTML5 videos wouldn't play when switching to new tab because callback function wasn't being called when video was ready --- js/video_player.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/js/video_player.js b/js/video_player.js index c4185e8a5f..f898b6e469 100644 --- a/js/video_player.js +++ b/js/video_player.js @@ -141,6 +141,7 @@ function setytplayerState(newState) { // IMPORTANT TODO: Load test // POSSIBLE FIX: Move to unload() event and similar var ajax_video=function(){}; +var ytplayer; function onYouTubePlayerReady(playerId) { ytplayer = document.getElementById("myytplayer"); @@ -166,6 +167,14 @@ function onYouTubePlayerAPIReady() { ajax_videoInterval = setInterval(ajax_video, 5000); } +// Need this function to call the API ready callback when we switch to a tab with AJAX that has a video +// That callback is not being fired when we switch tabs. +function loadHTML5Video() { + if (!ytplayer && switched_tab){ + onYouTubePlayerAPIReady(); + } +} + function onPlayerReady(event) { // alert("ready"); event.target.playVideo(); @@ -178,12 +187,15 @@ function onPlayerStateChange(event) { /* End HTML5 Specific */ + +var switched_tab = false; // switch to true when we destroy so we know to call onYouTubePlayerAPIReady() // clear pings to video status when we switch to a different sequence tab with ajax function videoDestroy() { load_id = 0; clearInterval(updateytplayerInfoInterval); clearInterval(ajax_videoInterval); ytplayer = false; + switched_tab = true; } function log_event(e, d) {