From 3e353300155fd348a49468f97eab2c22b1d27975 Mon Sep 17 00:00:00 2001
From: stevenaw
Date: Tue, 15 Mar 2011 20:25:36 -0400
Subject: [PATCH] [#140] Unit tests fixed
---
players/youtube/popcorn.youtube.html | 4 +-
players/youtube/popcorn.youtube.js | 91 ++++++++++++++++-------
players/youtube/popcorn.youtube.unit.html | 9 +--
players/youtube/popcorn.youtube.unit.js | 55 +++++++-------
4 files changed, 96 insertions(+), 63 deletions(-)
diff --git a/players/youtube/popcorn.youtube.html b/players/youtube/popcorn.youtube.html
index c7af417..3b3b5db 100644
--- a/players/youtube/popcorn.youtube.html
+++ b/players/youtube/popcorn.youtube.html
@@ -81,10 +81,10 @@
Due to the Flash security model, this demo must be run from a web server
From 5 to 40 seconds, the footnote 'The video is "RiP: A Remix Manifesto", by Brett Gaylor' will appear below 'Footnote Area'.
- Vimeo does not support their player to be chromeless (hidden controls), but custsom controls have been developed and tied into their player.
+ Youtube does not support their player to be chromeless (hidden controls), but custsom controls have been developed and tied into their player.
Clicking play/pause or seeking in either the video or via custsom controls will cause the other to update.
Clicking on the embed option in the Vimeo player while the video is playing will cause the video to pause and custom controls to update.
- The vimeo video can be specified in the HTML source by giving the vimeo web site url (http://vimeo.com/VIDEOID) to either the VimeoEngine or as the iframe src attribute.
+ The video can be specified in the HTML source by giving the vimeo web site url (http://www.youtube.com/watch?v=VIDEOID) to either Popcorn.youtube or as the div src attribute.
diff --git a/players/youtube/popcorn.youtube.js b/players/youtube/popcorn.youtube.js
index 473a43c..192c46f 100644
--- a/players/youtube/popcorn.youtube.js
+++ b/players/youtube/popcorn.youtube.js
@@ -59,8 +59,12 @@ var onYouTubePlayerReady;
var matches = url.match( /((http:\/\/)?www\.)?youtube\.[a-z]+\/watch\?v\=[a-z0-9]+/i );
+ if ( !matches ) {
+ return;
+ }
+
// Return id, which comes after first equals sign
- return !matches || matches[0].split( "=" )[1];
+ return matches[0].split( "=" )[1];
};
// Extract the id from a player url
@@ -71,8 +75,12 @@ var onYouTubePlayerReady;
var matches = url.match( /^http:\/\/?www\.youtube\.[a-z]+\/e\/[a-z0-9]+/i );
+ if ( !matches ) {
+ return;
+ }
+
// Return id, which comes after first equals sign
- return !matches || matches[0].split( "/e/" )[1];
+ return matches[0].split( "/e/" )[1];
};
function cueDelayedDurationCheck ( evt ) {
@@ -160,20 +168,10 @@ var onYouTubePlayerReady;
var self = this,
container = document.getElementById( elementId ),
+ src,
durEvtType;
-
- if ( !container ) {
- throw "Container ID could not be found";
- }
- // The video id for youtube (web or player formats)
- this.vidId = extractIdFromUrl( url ) || extractIdFromUri( url );
-
- if ( !this.vidId ) {
- throw "Must supply a video url!";
- }
-
- this.playerId = Popcorn.guid( elementId );
+ this.playerId = elementId;
this.readyState = READY_STATE_HAVE_NOTHING;
this.eventListeners = {};
this.loadStarted = false;
@@ -189,19 +187,62 @@ var onYouTubePlayerReady;
this.previousVolume = 0;
this.duration = Number.MAX_VALUE;
- this.addEventListener( "load", function() {
- self.video.cueVideoByUrl( getPlayerAddress( self.vidId ) );
- cueDelayedDurationCheck.call( self, "playing" );
- });
+ // The video id for youtube (web or player formats)
+ this.vidId = extractIdFromUrl( url ) || extractIdFromUri( url );
+
+ var loadByctor = !!this.vidId;
- this.video = createSWFObject({
- playerId: this.playerId,
- videoId: this.vidId,
- width: container.getAttribute("width") || 460,
- height: container.getAttribute("height") || 350
- });
+ // Container not yet loaded, load it on DOMDontentLoad
+ if ( container ) {
+ this.vidId = this.vidId || extractIdFromUrl( container.getAttribute( "src" ) ) || extractIdFromUri( container.getAttribute( "src" ) );
+
+ if ( !this.vidId ) {
+ throw "Could not find video id";
+ }
+
+ if ( container.children.length ) {
+ this.video = container.firstChild;
+ } else {
+ this.video = createSWFObject({
+ playerId: this.playerId,
+ videoId: this.vidId,
+ width: container.getAttribute("width") || 460,
+ height: container.getAttribute("height") || 350
+ });
+
+ container.appendChild( this.video );
+ }
+ } else {
+ document.addEventListener( "DOMContentLoaded", function() {
+ container = document.getElementById( elementId );
+
+ if ( !container ) {
+ throw "Could not find container!";
+ }
+
+ self.vidId = self.vidId || extractIdFromUrl( container.getAttribute( "src" ) ) || extractIdFromUri( container.getAttribute( "src" ) );
+
+ if ( !self.vidId ) {
+ throw "Could not find video id";
+ }
+
+ self.video = createSWFObject({
+ playerId: self.playerId,
+ videoId: self.vidId,
+ width: container.getAttribute("width") || 460,
+ height: container.getAttribute("height") || 350
+ });
+
+ container.appendChild( self.video );
+ }, false);
+ }
- container.appendChild( this.video );
+ if ( loadByctor ) {
+ this.addEventListener( "load", function() {
+ self.video.cueVideoByUrl( getPlayerAddress( self.vidId ) );
+ cueDelayedDurationCheck.call( self, "playing" );
+ });
+ }
registry[this.playerId] = this;
diff --git a/players/youtube/popcorn.youtube.unit.html b/players/youtube/popcorn.youtube.unit.html
index 93d5b1d..b6a1a4e 100644
--- a/players/youtube/popcorn.youtube.unit.html
+++ b/players/youtube/popcorn.youtube.unit.html
@@ -28,14 +28,7 @@
Therefore, if failures occur for the first time, just run it again. Likely,
failures would disappear the second time.
-
+