From 925d1c524f4d3e85376cd27e5337645d1bd79d1e Mon Sep 17 00:00:00 2001 From: Sylvain Chevalier Date: Thu, 7 May 2015 12:07:39 +0200 Subject: [PATCH 1/2] Removed dependency on deprecated Youtube data API v2. Retrieve video duration from player itself instead. --- .../popcorn.HTMLYouTubeVideoElement.js | 43 +++++++------------ 1 file changed, 16 insertions(+), 27 deletions(-) diff --git a/wrappers/youtube/popcorn.HTMLYouTubeVideoElement.js b/wrappers/youtube/popcorn.HTMLYouTubeVideoElement.js index cafed3c5c..c14b34cf6 100644 --- a/wrappers/youtube/popcorn.HTMLYouTubeVideoElement.js +++ b/wrappers/youtube/popcorn.HTMLYouTubeVideoElement.js @@ -256,6 +256,11 @@ function onBuffering() { impl.networkState = self.NETWORK_LOADING; + var newDuration = player.getDuration(); + if (impl.duration !== newDuration) { + impl.duration = newDuration; + self.dispatchEvent( "durationchange" ); + } self.dispatchEvent( "waiting" ); } @@ -406,38 +411,22 @@ // Get video ID out of youtube url aSrc = regexYouTube.exec( aSrc )[ 1 ]; - var xhrURL = "https://gdata.youtube.com/feeds/api/videos/" + aSrc + "?v=2&alt=jsonc&callback=?"; - // Get duration value. - Popcorn.getJSONP( xhrURL, function( resp ) { - - var warning = "failed to retreive duration data, reason: "; - if ( resp.error ) { - console.warn( warning + resp.error.message ); - return ; - } else if ( !resp.data ) { - console.warn( warning + "no response data" ); - return; + player = new YT.Player( elem, { + width: "100%", + height: "100%", + wmode: playerVars.wmode, + videoId: aSrc, + playerVars: playerVars, + events: { + 'onReady': onPlayerReady, + 'onError': onPlayerError, + 'onStateChange': onPlayerStateChange } - impl.duration = resp.data.duration; - self.dispatchEvent( "durationchange" ); - - player = new YT.Player( elem, { - width: "100%", - height: "100%", - wmode: playerVars.wmode, - videoId: aSrc, - playerVars: playerVars, - events: { - 'onReady': onPlayerReady, - 'onError': onPlayerError, - 'onStateChange': onPlayerStateChange - } - }); + }); impl.networkState = self.NETWORK_LOADING; self.dispatchEvent( "loadstart" ); self.dispatchEvent( "progress" ); - }); } function monitorCurrentTime() { From 8c632b42fe16354466a82e9ea4bd2c1bf137bad0 Mon Sep 17 00:00:00 2001 From: Sylvain Chevalier Date: Thu, 4 Jun 2015 09:06:26 +0200 Subject: [PATCH 2/2] Fixed indentation --- wrappers/youtube/popcorn.HTMLYouTubeVideoElement.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wrappers/youtube/popcorn.HTMLYouTubeVideoElement.js b/wrappers/youtube/popcorn.HTMLYouTubeVideoElement.js index c14b34cf6..4aeadba39 100644 --- a/wrappers/youtube/popcorn.HTMLYouTubeVideoElement.js +++ b/wrappers/youtube/popcorn.HTMLYouTubeVideoElement.js @@ -424,9 +424,9 @@ } }); - impl.networkState = self.NETWORK_LOADING; - self.dispatchEvent( "loadstart" ); - self.dispatchEvent( "progress" ); + impl.networkState = self.NETWORK_LOADING; + self.dispatchEvent( "loadstart" ); + self.dispatchEvent( "progress" ); } function monitorCurrentTime() {