}
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';
});
// 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() {
</head>
<body>
<div>
- <object id="video" type="application/x-shockwave-flash"
- data="http://www.youtube.com/e/ac7KhViaVqc?enablejsapi=1&playerapiid=video&version=3"
- width="250" height="200">
- <param name="allowFullScreen" value="true" />
- <param name="allowscriptaccess" value="always" />
- </object>
- </div>
- <div>
+ <div style="float:right;">
+ <h3>Description</h3>
+ <p>
+ 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.<br />
+ Due to the Flash security model, this demo must be run from a web server<br />
+ From 5 to 40 seconds, the footnote 'The video is "RiP: A Remix Manifesto", by Brett Gaylor' will appear below 'Footnote Area'.
+ <hr >
+ Vimeo does not support their player to be chromeless (hidden controls), but custsom controls have been developed and tied into their player.<br />
+ Clicking play/pause or seeking in either the video or via custsom controls will cause the other to update.<br />
+ 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.<br />
+ 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.<br/>
+ </p>
+ <br />
+ <br />
+ <br />
+ <div id="footnotediv" width="50%" height="50%">
+ <strong>Footnote Area</strong><br />
+ </div>
+ </div>
+ <div id="video" width="360" height="300" ></div>
<button class="simple" id="btn-play-pause">Play</button>
<button class="seek" id="btn-seek">Seek to 30</button>
<button class="volume" id="btn-volume">Toggle Volume</button>
<ul>
<li>Status: <span id="player-status">Not Ready</span></li>
<li>Current Time (s): <span id="player-time"></span></li>
+ <li>Volume (0-1): <span id="player_vol"></span></li>
<li>Video Duration (s): <span id="player-duration"></span></li>
</ul>
</div>
- Footnote:<br />
- <div id="footnotediv" width="50%" height="50%"></div>
</div>
</body>
</html>
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;
this.eventListeners[evt].unshift(durSetEvt);
}
+ /*
+ <object id="video" type="application/x-shockwave-flash"
+ data="http://www.youtube.com/e/ac7KhViaVqc?enablejsapi=1&playerapiid=video&version=3"
+ width="250" height="200">
+ <param name="allowFullScreen" value="true" />
+ <param name="allowscriptaccess" value="always" />
+ </object>*/
+
+ 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 ) {
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;
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" );
}
};
// 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 );
}
},