From: stevenaw Date: Tue, 15 Mar 2011 22:20:36 +0000 (-0400) Subject: [#140] Server detection, object embedding, and mute fix and UI tweaks X-Git-Tag: v0.4~7^2~4 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=e237cbf96914b2861b436495fb40fd19a5b83168;p=popcorn-js.git [#140] Server detection, object embedding, and mute fix and UI tweaks --- diff --git a/players/youtube/popcorn.youtube.html b/players/youtube/popcorn.youtube.html index d874f24..c7af417 100644 --- a/players/youtube/popcorn.youtube.html +++ b/players/youtube/popcorn.youtube.html @@ -12,32 +12,30 @@ } document.addEventListener( 'DOMContentLoaded', function() { - var popcorn = Popcorn( Popcorn.youtube( 'video', 'http://www.youtube.com/watch?v=9oar9glUCL0' ) ); + var popcorn = Popcorn( Popcorn.youtube( 'video', 'http://www.youtube.com/watch?v=9oar9glUCL0' ) ), + paused = true; - - popcorn.footnote({ + popcorn = popcorn.footnote({ start: 5, // seconds - end: 15, // seconds - text: 'Visit webmademovies.org for more details', + end: 40, // seconds + text: 'The video is "RiP: A Remix Manifesto", by Brett Gaylor', target: 'footnotediv' - }); - - popcorn.listen( 'durationchange', function() { + }) + .listen( 'durationchange', function() { element( 'player-duration' ).innerHTML = popcorn.duration(); - }); - - // Update time - popcorn.listen( 'timeupdate', function() { + }) + .listen( 'volumechange', function() { + element( 'player_vol' ).innerHTML = popcorn.volume(); + }) + .listen( 'timeupdate', function() { element( 'player-time' ).innerHTML = popcorn.currentTime(); - }); - + }) // Update button labels - var paused = true; - popcorn.listen( 'playing' , function() { + .listen( 'playing' , function() { paused = false; element( 'btn-play-pause' ).innerHTML = 'Pause'; - }); - popcorn.listen('pause', function() { + }) + .listen('pause', function() { paused = true; element( 'btn-play-pause' ).innerHTML = 'Play'; }); @@ -45,6 +43,7 @@ // Setup UI after loaded popcorn.listen( 'load', function() { element( 'player-status' ).innerHTML = 'Ready'; + element( 'player_vol' ).innerHTML = popcorn.volume(); // Single play/pause button element( 'btn-play-pause' ).addEventListener( 'click', function() { @@ -75,14 +74,26 @@
- - - - -
-
+
+

Description

+

+ This demo will showcase how a Youtube flash video can be integrated into Popcorn. This is done by making the flash video masquerade as HTML 5 video.
+ 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.
+ 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.
+

+
+
+
+
+ Footnote Area
+
+
+
@@ -91,11 +102,10 @@
- Footnote:
-
diff --git a/players/youtube/popcorn.youtube.js b/players/youtube/popcorn.youtube.js index 26b345c..473a43c 100644 --- a/players/youtube/popcorn.youtube.js +++ b/players/youtube/popcorn.youtube.js @@ -63,6 +63,18 @@ var onYouTubePlayerReady; return !matches || matches[0].split( "=" )[1]; }; + // Extract the id from a player url + function extractIdFromUri( url ) { + if ( !url ) { + return; + } + + var matches = url.match( /^http:\/\/?www\.youtube\.[a-z]+\/e\/[a-z0-9]+/i ); + + // Return id, which comes after first equals sign + return !matches || matches[0].split( "/e/" )[1]; + }; + function cueDelayedDurationCheck ( evt ) { var self = this, durSetEvt; @@ -76,6 +88,36 @@ var onYouTubePlayerReady; this.eventListeners[evt].unshift(durSetEvt); } + /* + + + + */ + + function createSWFObject( params ) { + var obj = document.createElement( "object" ); + + obj.setAttribute( "id", params.playerId ); + obj.setAttribute( "type", "application/x-shockwave-flash" ); + obj.setAttribute( "data", getPlayerAddress( params.videoId ) + "?enablejsapi=1&playerapiid=" + params.playerId ); + obj.setAttribute( "width", params.width ); + obj.setAttribute( "height", params.height ); + + var param1 = document.createElement( "param" ); + param1.setAttribute( "name", "allowFullScreen" ); + param1.setAttribute( "value", "true" ); + + var param2 = document.createElement( "param" ); + param2.setAttribute( "name", "allowscriptaccess" ); + param2.setAttribute( "value", "always" ); + + obj.appendChild( param1 ); + obj.appendChild( param2 ); + + return obj; + } function getPlayerAddress( id ) { if( !id ) { @@ -112,12 +154,26 @@ var onYouTubePlayerReady; Popcorn.youtube.init = function( elementId, url ) { if ( !elementId ) { throw "Element id is invalid."; + } else if ( /file/.test( location.protocol ) ) { + throw "This must be run from a web server."; } var self = this, + container = document.getElementById( elementId ), durEvtType; - - this.video = document.getElementById( elementId ); + + 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.readyState = READY_STATE_HAVE_NOTHING; this.eventListeners = {}; this.loadStarted = false; @@ -126,29 +182,30 @@ var onYouTubePlayerReady; this.timeUpdater = null; this.progressUpdater = null; + this.preMuteVol = 0; this.currentTime = 0; this.previousCurrentTime = 0; this.volume = 0; - this.previousVolume = 0; - - this.playerId = elementId; + this.previousVolume = 0; this.duration = Number.MAX_VALUE; - // The video id for youtube - this.vidId = extractIdFromUrl( url ); + this.addEventListener( "load", function() { + self.video.cueVideoByUrl( getPlayerAddress( self.vidId ) ); + cueDelayedDurationCheck.call( self, "playing" ); + }); - if ( this.vidId ) { - this.addEventListener( "load", function() { - self.video.cueVideoByUrl( getPlayerAddress( self.vidId ) ); - cueDelayedDurationCheck.call( self, "playing" ); - }); - } else { - cueDelayedDurationCheck.call( this, "load" ); - } + this.video = createSWFObject({ + playerId: this.playerId, + videoId: this.vidId, + width: container.getAttribute("width") || 460, + height: container.getAttribute("height") || 350 + }); + + container.appendChild( this.video ); - registry[elementId] = this; + registry[this.playerId] = this; - if ( loadedPlayers[elementId] ) { + if ( loadedPlayers[this.playerId] ) { this.dispatchEvent( "load" ); } }; @@ -253,14 +310,11 @@ var onYouTubePlayerReady; // Mute is toggleable mute: function() { - if ( this.video.isMuted() ) { - this.video.unMute(); - this.volume = this.video.getVolume() / 100; - this.dispatchEvent( 'volumechange' ); + if ( this.volume !== 0 ) { + this.preMuteVol = this.volume; + this.setVolume( 0 ); } else { - this.video.mute(); - this.volume = 0; - this.dispatchEvent( 'volumechange' ); + this.setVolume( this.preMuteVol ); } },