Skip to content
Browse files

initial commit

  • Loading branch information...
0 parents commit 860a8fd2a3e1640e83aa0b815bc2bfa0fbab14d1 @bdougherty bdougherty committed Mar 25, 2011
BIN actionscript/.DS_Store
Binary file not shown.
BIN actionscript/ant/.DS_Store
Binary file not shown.
48 actionscript/ant/build/build.xml
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?><!--ant-->
+<!--
+ Created by Ryan Hefner on 2011-03-25.
+ Copyright (c) 2010-2011 Vimeo. All rights reserved.
+-->
+<project name="Flash API Example" default="compile" basedir="../../">
+ <description>Build and deploy the Flash API Example swf.</description>
+
+ <property file="ant/properties/build.properties" />
+
+ <!-- Moogaloop Properties -->
+ <property name="swfname" value="flash_api_example.swf" />
+ <property name="link-report" value="link_report.txt" />
+
+ <!-- General Player Properties -->
+ <property name="width" value="640" />
+ <property name="height" value="360" />
+
+ <!-- Targets -->
+ <target name="compile">
+ <exec executable="${mxmlc.sv}">
+ <arg value="-as3=true" />
+ <arg value="-compatibility-version=3.0.0" />
+ <arg value="-source-path" />
+ <arg value="${classroot.dir}" />
+ <arg value="-library-path" />
+ <arg value="${libs.sv.dir}" />
+ <arg line="-swf-version=11" />
+ <arg line="-target-player=${sv_targetplayer}" />
+ <arg line="-default-frame-rate=${framerate}" />
+ <arg line="-default-background-color=${bgcolor}" />
+ <arg value="-default-size" />
+ <arg value="${width}" />
+ <arg value="${height}" />
+ <arg line="-debug=false" />
+ <arg line="-optimize=true" />
+ <arg line="-strict=true" />
+ <arg line="-warnings=false" />
+ <arg line="-show-unused-type-selector-warnings=true" />
+ <arg value="${classroot.dir}/com/vimeo/example/ExampleProject.as" />
+ <arg value="-output" />
+ <arg value="${root.dir}/deploy/${swfname}" />
+ <arg value="-link-report" />
+ <arg value="${reports.dir}/${link-report}" />
+ <arg value="-static-link-runtime-shared-libraries" />
+ </exec>
+ </target>
+</project>
28 actionscript/ant/properties/build.properties
@@ -0,0 +1,28 @@
+#Point this to the location where you installed the Flex SDK
+#SDK Properties
+
+# Flex SDK
+sdkhome.sv.dir = YOUR FLEX SDK PATH
+bin.sv.dir = ${sdkhome.sv.dir}/bin
+libs.sv.dir = ${sdkhome.sv.dir}/frameworks/libs
+flashplayer.sv = ${sdkhome.sv.dir}/runtimes/player/mac/Flash\ Player.app
+mxmlc.sv = ${bin.sv.dir}/mxmlc
+compc.sv = ${bin.sv.dir}/compc
+asdoc.sv = ${bin.sv.dir}/asdoc
+
+# Aplication Settings
+version.num = 1.0.0
+
+#You shouldn't need to change any of these properties unless the structure of the app changes.
+#Directories
+build.dir = build
+root.dir = .
+classroot.dir = ${root.dir}/src
+approot.dir = ${root.dir}/flash
+reports.dir = ${root.dir}/ant/reports
+
+#Project Properties
+framerate = 30
+bgcolor = 0x000000
+targetplayer = 10.0.0
+sv_targetplayer = 10.2.0
43 actionscript/ant/reports/link_report.txt
@@ -0,0 +1,43 @@
+<report>
+ <scripts>
+ <script name="/Users/ryanhefner/Documents/public_html/flash/flash_api_example/flash_api_example/src/com/vimeo/api/VimeoPlayer.as" mod="1301085490000" size="4123" optimizedsize="3936">
+ <def id="com.vimeo.api:VimeoPlayer" />
+ <pre id="flash.display:Sprite" />
+ <dep id="flash.events:Event" />
+ <dep id="flash.events:MouseEvent" />
+ <dep id="flash.net:URLRequest" />
+ <dep id="flash.system:Security" />
+ <dep id="AS3" />
+ <dep id="flash.display:DisplayObject" />
+ <dep id="flash.utils:Timer" />
+ <dep id="Math" />
+ <dep id="flash.events:TimerEvent" />
+ <dep id="flash.display:Loader" />
+ <dep id="flash.geom:Point" />
+ </script>
+ <script name="/Users/ryanhefner/Documents/public_html/flash/flash_api_example/flash_api_example/src/com/vimeo/example/ExampleProject.as" mod="1301084391000" size="577" optimizedsize="553">
+ <def id="com.vimeo.example:ExampleProject" />
+ <pre id="flash.display:Sprite" />
+ <dep id="flash.display:StageScaleMode" />
+ <dep id="AS3" />
+ <dep id="com.vimeo.api:VimeoPlayer" />
+ <dep id="flash.display:StageAlign" />
+ </script>
+ </scripts>
+ <external-defs>
+ <ext id="flash.display:StageAlign" />
+ <ext id="AS3" />
+ <ext id="flash.display:DisplayObject" />
+ <ext id="flash.utils:Timer" />
+ <ext id="flash.geom:Point" />
+ <ext id="flash.events:MouseEvent" />
+ <ext id="flash.display:StageScaleMode" />
+ <ext id="Math" />
+ <ext id="flash.events:Event" />
+ <ext id="flash.net:URLRequest" />
+ <ext id="flash.events:TimerEvent" />
+ <ext id="flash.display:Sprite" />
+ <ext id="flash.display:Loader" />
+ <ext id="flash.system:Security" />
+ </external-defs>
+</report>
BIN actionscript/deploy/.DS_Store
Binary file not shown.
BIN actionscript/deploy/assets/js/.DS_Store
Binary file not shown.
4 actionscript/deploy/assets/js/swfobject.js
@@ -0,0 +1,4 @@
+/* SWFObject v2.2 <http://code.google.com/p/swfobject/>
+ is released under the MIT License <http://www.opensource.org/licenses/mit-license.php>
+*/
+var swfobject=function(){var D="undefined",r="object",S="Shockwave Flash",W="ShockwaveFlash.ShockwaveFlash",q="application/x-shockwave-flash",R="SWFObjectExprInst",x="onreadystatechange",O=window,j=document,t=navigator,T=false,U=[h],o=[],N=[],I=[],l,Q,E,B,J=false,a=false,n,G,m=true,M=function(){var aa=typeof j.getElementById!=D&&typeof j.getElementsByTagName!=D&&typeof j.createElement!=D,ah=t.userAgent.toLowerCase(),Y=t.platform.toLowerCase(),ae=Y?/win/.test(Y):/win/.test(ah),ac=Y?/mac/.test(Y):/mac/.test(ah),af=/webkit/.test(ah)?parseFloat(ah.replace(/^.*webkit\/(\d+(\.\d+)?).*$/,"$1")):false,X=!+"\v1",ag=[0,0,0],ab=null;if(typeof t.plugins!=D&&typeof t.plugins[S]==r){ab=t.plugins[S].description;if(ab&&!(typeof t.mimeTypes!=D&&t.mimeTypes[q]&&!t.mimeTypes[q].enabledPlugin)){T=true;X=false;ab=ab.replace(/^.*\s+(\S+\s+\S+$)/,"$1");ag[0]=parseInt(ab.replace(/^(.*)\..*$/,"$1"),10);ag[1]=parseInt(ab.replace(/^.*\.(.*)\s.*$/,"$1"),10);ag[2]=/[a-zA-Z]/.test(ab)?parseInt(ab.replace(/^.*[a-zA-Z]+(.*)$/,"$1"),10):0}}else{if(typeof O.ActiveXObject!=D){try{var ad=new ActiveXObject(W);if(ad){ab=ad.GetVariable("$version");if(ab){X=true;ab=ab.split(" ")[1].split(",");ag=[parseInt(ab[0],10),parseInt(ab[1],10),parseInt(ab[2],10)]}}}catch(Z){}}}return{w3:aa,pv:ag,wk:af,ie:X,win:ae,mac:ac}}(),k=function(){if(!M.w3){return}if((typeof j.readyState!=D&&j.readyState=="complete")||(typeof j.readyState==D&&(j.getElementsByTagName("body")[0]||j.body))){f()}if(!J){if(typeof j.addEventListener!=D){j.addEventListener("DOMContentLoaded",f,false)}if(M.ie&&M.win){j.attachEvent(x,function(){if(j.readyState=="complete"){j.detachEvent(x,arguments.callee);f()}});if(O==top){(function(){if(J){return}try{j.documentElement.doScroll("left")}catch(X){setTimeout(arguments.callee,0);return}f()})()}}if(M.wk){(function(){if(J){return}if(!/loaded|complete/.test(j.readyState)){setTimeout(arguments.callee,0);return}f()})()}s(f)}}();function f(){if(J){return}try{var Z=j.getElementsByTagName("body")[0].appendChild(C("span"));Z.parentNode.removeChild(Z)}catch(aa){return}J=true;var X=U.length;for(var Y=0;Y<X;Y++){U[Y]()}}function K(X){if(J){X()}else{U[U.length]=X}}function s(Y){if(typeof O.addEventListener!=D){O.addEventListener("load",Y,false)}else{if(typeof j.addEventListener!=D){j.addEventListener("load",Y,false)}else{if(typeof O.attachEvent!=D){i(O,"onload",Y)}else{if(typeof O.onload=="function"){var X=O.onload;O.onload=function(){X();Y()}}else{O.onload=Y}}}}}function h(){if(T){V()}else{H()}}function V(){var X=j.getElementsByTagName("body")[0];var aa=C(r);aa.setAttribute("type",q);var Z=X.appendChild(aa);if(Z){var Y=0;(function(){if(typeof Z.GetVariable!=D){var ab=Z.GetVariable("$version");if(ab){ab=ab.split(" ")[1].split(",");M.pv=[parseInt(ab[0],10),parseInt(ab[1],10),parseInt(ab[2],10)]}}else{if(Y<10){Y++;setTimeout(arguments.callee,10);return}}X.removeChild(aa);Z=null;H()})()}else{H()}}function H(){var ag=o.length;if(ag>0){for(var af=0;af<ag;af++){var Y=o[af].id;var ab=o[af].callbackFn;var aa={success:false,id:Y};if(M.pv[0]>0){var ae=c(Y);if(ae){if(F(o[af].swfVersion)&&!(M.wk&&M.wk<312)){w(Y,true);if(ab){aa.success=true;aa.ref=z(Y);ab(aa)}}else{if(o[af].expressInstall&&A()){var ai={};ai.data=o[af].expressInstall;ai.width=ae.getAttribute("width")||"0";ai.height=ae.getAttribute("height")||"0";if(ae.getAttribute("class")){ai.styleclass=ae.getAttribute("class")}if(ae.getAttribute("align")){ai.align=ae.getAttribute("align")}var ah={};var X=ae.getElementsByTagName("param");var ac=X.length;for(var ad=0;ad<ac;ad++){if(X[ad].getAttribute("name").toLowerCase()!="movie"){ah[X[ad].getAttribute("name")]=X[ad].getAttribute("value")}}P(ai,ah,Y,ab)}else{p(ae);if(ab){ab(aa)}}}}}else{w(Y,true);if(ab){var Z=z(Y);if(Z&&typeof Z.SetVariable!=D){aa.success=true;aa.ref=Z}ab(aa)}}}}}function z(aa){var X=null;var Y=c(aa);if(Y&&Y.nodeName=="OBJECT"){if(typeof Y.SetVariable!=D){X=Y}else{var Z=Y.getElementsByTagName(r)[0];if(Z){X=Z}}}return X}function A(){return !a&&F("6.0.65")&&(M.win||M.mac)&&!(M.wk&&M.wk<312)}function P(aa,ab,X,Z){a=true;E=Z||null;B={success:false,id:X};var ae=c(X);if(ae){if(ae.nodeName=="OBJECT"){l=g(ae);Q=null}else{l=ae;Q=X}aa.id=R;if(typeof aa.width==D||(!/%$/.test(aa.width)&&parseInt(aa.width,10)<310)){aa.width="310"}if(typeof aa.height==D||(!/%$/.test(aa.height)&&parseInt(aa.height,10)<137)){aa.height="137"}j.title=j.title.slice(0,47)+" - Flash Player Installation";var ad=M.ie&&M.win?"ActiveX":"PlugIn",ac="MMredirectURL="+O.location.toString().replace(/&/g,"%26")+"&MMplayerType="+ad+"&MMdoctitle="+j.title;if(typeof ab.flashvars!=D){ab.flashvars+="&"+ac}else{ab.flashvars=ac}if(M.ie&&M.win&&ae.readyState!=4){var Y=C("div");X+="SWFObjectNew";Y.setAttribute("id",X);ae.parentNode.insertBefore(Y,ae);ae.style.display="none";(function(){if(ae.readyState==4){ae.parentNode.removeChild(ae)}else{setTimeout(arguments.callee,10)}})()}u(aa,ab,X)}}function p(Y){if(M.ie&&M.win&&Y.readyState!=4){var X=C("div");Y.parentNode.insertBefore(X,Y);X.parentNode.replaceChild(g(Y),X);Y.style.display="none";(function(){if(Y.readyState==4){Y.parentNode.removeChild(Y)}else{setTimeout(arguments.callee,10)}})()}else{Y.parentNode.replaceChild(g(Y),Y)}}function g(ab){var aa=C("div");if(M.win&&M.ie){aa.innerHTML=ab.innerHTML}else{var Y=ab.getElementsByTagName(r)[0];if(Y){var ad=Y.childNodes;if(ad){var X=ad.length;for(var Z=0;Z<X;Z++){if(!(ad[Z].nodeType==1&&ad[Z].nodeName=="PARAM")&&!(ad[Z].nodeType==8)){aa.appendChild(ad[Z].cloneNode(true))}}}}}return aa}function u(ai,ag,Y){var X,aa=c(Y);if(M.wk&&M.wk<312){return X}if(aa){if(typeof ai.id==D){ai.id=Y}if(M.ie&&M.win){var ah="";for(var ae in ai){if(ai[ae]!=Object.prototype[ae]){if(ae.toLowerCase()=="data"){ag.movie=ai[ae]}else{if(ae.toLowerCase()=="styleclass"){ah+=' class="'+ai[ae]+'"'}else{if(ae.toLowerCase()!="classid"){ah+=" "+ae+'="'+ai[ae]+'"'}}}}}var af="";for(var ad in ag){if(ag[ad]!=Object.prototype[ad]){af+='<param name="'+ad+'" value="'+ag[ad]+'" />'}}aa.outerHTML='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'+ah+">"+af+"</object>";N[N.length]=ai.id;X=c(ai.id)}else{var Z=C(r);Z.setAttribute("type",q);for(var ac in ai){if(ai[ac]!=Object.prototype[ac]){if(ac.toLowerCase()=="styleclass"){Z.setAttribute("class",ai[ac])}else{if(ac.toLowerCase()!="classid"){Z.setAttribute(ac,ai[ac])}}}}for(var ab in ag){if(ag[ab]!=Object.prototype[ab]&&ab.toLowerCase()!="movie"){e(Z,ab,ag[ab])}}aa.parentNode.replaceChild(Z,aa);X=Z}}return X}function e(Z,X,Y){var aa=C("param");aa.setAttribute("name",X);aa.setAttribute("value",Y);Z.appendChild(aa)}function y(Y){var X=c(Y);if(X&&X.nodeName=="OBJECT"){if(M.ie&&M.win){X.style.display="none";(function(){if(X.readyState==4){b(Y)}else{setTimeout(arguments.callee,10)}})()}else{X.parentNode.removeChild(X)}}}function b(Z){var Y=c(Z);if(Y){for(var X in Y){if(typeof Y[X]=="function"){Y[X]=null}}Y.parentNode.removeChild(Y)}}function c(Z){var X=null;try{X=j.getElementById(Z)}catch(Y){}return X}function C(X){return j.createElement(X)}function i(Z,X,Y){Z.attachEvent(X,Y);I[I.length]=[Z,X,Y]}function F(Z){var Y=M.pv,X=Z.split(".");X[0]=parseInt(X[0],10);X[1]=parseInt(X[1],10)||0;X[2]=parseInt(X[2],10)||0;return(Y[0]>X[0]||(Y[0]==X[0]&&Y[1]>X[1])||(Y[0]==X[0]&&Y[1]==X[1]&&Y[2]>=X[2]))?true:false}function v(ac,Y,ad,ab){if(M.ie&&M.mac){return}var aa=j.getElementsByTagName("head")[0];if(!aa){return}var X=(ad&&typeof ad=="string")?ad:"screen";if(ab){n=null;G=null}if(!n||G!=X){var Z=C("style");Z.setAttribute("type","text/css");Z.setAttribute("media",X);n=aa.appendChild(Z);if(M.ie&&M.win&&typeof j.styleSheets!=D&&j.styleSheets.length>0){n=j.styleSheets[j.styleSheets.length-1]}G=X}if(M.ie&&M.win){if(n&&typeof n.addRule==r){n.addRule(ac,Y)}}else{if(n&&typeof j.createTextNode!=D){n.appendChild(j.createTextNode(ac+" {"+Y+"}"))}}}function w(Z,X){if(!m){return}var Y=X?"visible":"hidden";if(J&&c(Z)){c(Z).style.visibility=Y}else{v("#"+Z,"visibility:"+Y)}}function L(Y){var Z=/[\\\"<>\.;]/;var X=Z.exec(Y)!=null;return X&&typeof encodeURIComponent!=D?encodeURIComponent(Y):Y}var d=function(){if(M.ie&&M.win){window.attachEvent("onunload",function(){var ac=I.length;for(var ab=0;ab<ac;ab++){I[ab][0].detachEvent(I[ab][1],I[ab][2])}var Z=N.length;for(var aa=0;aa<Z;aa++){y(N[aa])}for(var Y in M){M[Y]=null}M=null;for(var X in swfobject){swfobject[X]=null}swfobject=null})}}();return{registerObject:function(ab,X,aa,Z){if(M.w3&&ab&&X){var Y={};Y.id=ab;Y.swfVersion=X;Y.expressInstall=aa;Y.callbackFn=Z;o[o.length]=Y;w(ab,false)}else{if(Z){Z({success:false,id:ab})}}},getObjectById:function(X){if(M.w3){return z(X)}},embedSWF:function(ab,ah,ae,ag,Y,aa,Z,ad,af,ac){var X={success:false,id:ah};if(M.w3&&!(M.wk&&M.wk<312)&&ab&&ah&&ae&&ag&&Y){w(ah,false);K(function(){ae+="";ag+="";var aj={};if(af&&typeof af===r){for(var al in af){aj[al]=af[al]}}aj.data=ab;aj.width=ae;aj.height=ag;var am={};if(ad&&typeof ad===r){for(var ak in ad){am[ak]=ad[ak]}}if(Z&&typeof Z===r){for(var ai in Z){if(typeof am.flashvars!=D){am.flashvars+="&"+ai+"="+Z[ai]}else{am.flashvars=ai+"="+Z[ai]}}}if(F(Y)){var an=u(aj,am,ah);if(aj.id==ah){w(ah,true)}X.success=true;X.ref=an}else{if(aa&&A()){aj.data=aa;P(aj,am,ah,ac);return}else{w(ah,true)}}if(ac){ac(X)}})}else{if(ac){ac(X)}}},switchOffAutoHideShow:function(){m=false},ua:M,getFlashPlayerVersion:function(){return{major:M.pv[0],minor:M.pv[1],release:M.pv[2]}},hasFlashPlayerVersion:F,createSWF:function(Z,Y,X){if(M.w3){return u(Z,Y,X)}else{return undefined}},showExpressInstall:function(Z,aa,X,Y){if(M.w3&&A()){P(Z,aa,X,Y)}},removeSWF:function(X){if(M.w3){y(X)}},createCSS:function(aa,Z,Y,X){if(M.w3){v(aa,Z,Y,X)}},addDomLoadEvent:K,addLoadEvent:s,getQueryParamValue:function(aa){var Z=j.location.search||j.location.hash;if(Z){if(/\?/.test(Z)){Z=Z.split("?")[1]}if(aa==null){return L(Z)}var Y=Z.split("&");for(var X=0;X<Y.length;X++){if(Y[X].substring(0,Y[X].indexOf("="))==aa){return L(Y[X].substring((Y[X].indexOf("=")+1)))}}}return""},expressInstallCallback:function(){if(a){var X=c(R);if(X&&l){X.parentNode.replaceChild(l,X);if(Q){w(Q,true);if(M.ie&&M.win){l.style.display="block"}}if(E){E(B)}}a=false}}}}();
BIN actionscript/deploy/assets/swf/expressInstall.swf
Binary file not shown.
BIN actionscript/deploy/flash_api_example.swf
Binary file not shown.
38 actionscript/deploy/index.html
@@ -0,0 +1,38 @@
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
+<title>Vimeo: Flash API Example</title>
+</head>
+<body>
+<div id="player">
+ <noscript>
+ <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" width="640" height="360" id="flash_api_example" align="middle">
+ <param name="allowScriptAccess" value="always" />
+ <param name="allowFullScreen" value="true" />
+ <param name="movie" value="flash_api_example.swf" />
+ <param name="quality" value="high" />
+ <param name="bgcolor" value="#000000" />
+ <embed src="flash_api_example.swf" quality="high" bgcolor="#000000" width="640" height="360" name="flash_api_example" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" />
+ </object>
+ </noscript>
+</div>
+<script type="text/javascript" src="assets/js/swfobject.js"></script>
+<script type="text/javascript" language="javascript">
+ var flashvars = {};
+
+ var params = {
+ bgcolor: "#000000",
+ wmode: "opaque",
+ allowscriptaccess: "always",
+ allowfullscreen: true
+ };
+
+ var attributes = {
+ id: "flash_api_example",
+ name: "flash_api_example"
+ };
+
+ swfobject.embedSWF("flash_api_example.swf", "player", "640", "360", "10.0.0", "assets/swf/expressInstall.swf", flashvars, params, attributes);
+</script>
+</body>
+</html>
BIN actionscript/flash/flash_api_example.fla
Binary file not shown.
0 actionscript/readme
No changes.
345 actionscript/src/com/vimeo/api/VimeoPlayer.as
@@ -0,0 +1,345 @@
+/**
+ * VimeoPlayer
+ *
+ * A wrapper class for Vimeo's video player (codenamed Moogaloop)
+ * that allows you to embed easily into any AS3 application.
+ *
+ * Example on how to use:
+ * var vimeo_player = new VimeoPlayer([YOUR_APPLICATIONS_CONSUMER_KEY], 2, 400, 300);
+ * vimeo_player.addEventListener(Event.COMPLETE, vimeoPlayerLoaded);
+ * addChild(vimeo_player);
+ *
+ * http://vimeo.com/api/docs/moogaloop
+ *
+ * Register your application for access to the Moogaloop API at:
+ *
+ * http://vimeo.com/api/applications
+ */
+package com.vimeo.api
+{
+ import flash.net.URLRequest;
+ import flash.display.DisplayObject;
+ import flash.display.Loader;
+ import flash.display.Sprite;
+ import flash.events.Event;
+ import flash.events.TimerEvent;
+ import flash.events.MouseEvent;
+ import flash.external.ExternalInterface;
+ import flash.geom.Point;
+ import flash.utils.Timer;
+ import flash.system.ApplicationDomain;
+ import flash.system.LoaderContext;
+ import flash.system.Security;
+ import flash.system.SecurityDomain;
+
+
+ public class VimeoPlayer extends Sprite {
+
+ // Assets
+ private var container : Sprite = new Sprite(); // sprite that holds the player
+ private var moogaloop : Object = false; // the player
+ private var player_mask : Sprite = new Sprite(); // some sprites inside moogaloop go outside the bounds of the player. we use a mask to hide it
+
+ // Default variables
+ private var player_width : int = 400;
+ private var player_height : int = 300;
+ private var api_version : int = 2;
+ private var load_timer : Timer = new Timer(200);
+
+ // Events
+ // API v2
+ public static const FINISH : String = 'finish';
+ public static const LOAD_PROGRESS : String = 'loadProgress';
+ public static const PAUSE : String = 'pause';
+ public static const PLAY : String = 'play';
+ public static const PLAY_PROGRESS : String = 'playProgress';
+ public static const READY : String = 'ready';
+ public static const SEEK : String = 'seek';
+
+ // API v1
+ public static const ON_FINISH : String = 'onFinish';
+ public static const ON_LOADING : String = 'onLoading';
+ public static const ON_PAUSE : String = 'onPause';
+ public static const ON_PLAY : String = 'onPlay';
+ public static const ON_PROGRESS : String = 'onProgress';
+ public static const ON_SEEK : String = 'onSeek';
+
+
+ public function VimeoPlayer(oauth_key:String, clip_id:int, w:int, h:int, fp_version:String='10', api_version:int=2)
+ {
+ this.setDimensions(w, h);
+
+ Security.allowDomain('*');
+ Security.loadPolicyFile('http://api.vimeo.com/crossdomain.xml');
+
+ var api_param : String = '&js_api=1';
+
+ //
+ if (fp_version != '9')
+ {
+ switch(api_version)
+ {
+ case 2:
+ api_param = '&api=1';
+ break;
+ }
+ }
+
+ // var loaderContext : LoaderContext = new LoaderContext(true, ApplicationDomain.currentDomain, SecurityDomain.currentDomain);
+
+ var request : URLRequest = new URLRequest("http://api.vimeo.com/moogaloop_api.swf?oauth_key=" + oauth_key + "&clip_id=" + clip_id + "&width=" + w + "&height=" + h + "&fullscreen=0&fp_version=" + fp_version + api_param + "&cache_buster=" + (Math.random() * 1000));
+
+ var loader : Loader = new Loader();
+ loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete, false, 0, true);
+ loader.load(request);
+ }
+
+ public function destroy() : void
+ {
+ if (api_version == 2)
+ {
+ // API v2 Event Handlers
+ moogaloop.removeEventListener(READY, readyHandler);
+ moogaloop.removeEventListener(PLAY, playHandler);
+ moogaloop.removeEventListener(PAUSE, pauseHandler);
+ moogaloop.removeEventListener(SEEK, seekHandler);
+ moogaloop.removeEventListener(LOAD_PROGRESS, loadProgressHandler);
+ moogaloop.removeEventListener(PLAY_PROGRESS, playProgressHandler);
+ moogaloop.removeEventListener(FINISH, finishHandler);
+ }
+ else
+ {
+ // API v1 Event Handlers
+ moogaloop.removeEventListener(ON_PLAY, onPlayHandler);
+ moogaloop.removeEventListener(ON_PAUSE, onPauseHandler);
+ moogaloop.removeEventListener(ON_SEEK, onSeekHandler);
+ moogaloop.removeEventListener(ON_LOADING, onLoadingHandler);
+ moogaloop.removeEventListener(ON_PROGRESS, onProgressHandler);
+ moogaloop.removeEventListener(ON_FINISH, onFinishHandler);
+ }
+
+ moogaloop.destroy();
+ if (container.contains(DisplayObject(moogaloop))) container.removeChild(DisplayObject(moogaloop));
+ if (this.contains(player_mask)) this.removeChild(player_mask);
+ if (this.contains(container)) this.removeChild(container);
+
+ stage.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMove);
+ }
+
+ private function setDimensions(w:int, h:int) : void
+ {
+ player_width = w;
+ player_height = h;
+ }
+
+ private function onComplete(e:Event) : void
+ {
+ // Finished loading moogaloop
+ container.addChild(e.currentTarget.loader.content);
+ moogaloop = e.currentTarget.loader.content;
+
+ if (api_version == 2)
+ {
+ // API v2 Event Handlers
+ moogaloop.addEventListener(READY, readyHandler, false, 0, true);
+ moogaloop.addEventListener(PLAY, playHandler, false, 0, true);
+ moogaloop.addEventListener(PAUSE, pauseHandler, false, 0, true);
+ moogaloop.addEventListener(SEEK, seekHandler, false, 0, true);
+ moogaloop.addEventListener(LOAD_PROGRESS, loadProgressHandler, false, 0, true);
+ moogaloop.addEventListener(PLAY_PROGRESS, playProgressHandler, false, 0, true);
+ moogaloop.addEventListener(FINISH, finishHandler, false, 0, true);
+ }
+ else
+ {
+ // API v1 Event Handlers
+ moogaloop.addEventListener(ON_PLAY, onPlayHandler, false, 0, true);
+ moogaloop.addEventListener(ON_PAUSE, onPauseHandler, false, 0, true);
+ moogaloop.addEventListener(ON_SEEK, onSeekHandler, false, 0, true);
+ moogaloop.addEventListener(ON_LOADING, onLoadingHandler, false, 0, true);
+ moogaloop.addEventListener(ON_PROGRESS, onProgressHandler, false, 0, true);
+ moogaloop.addEventListener(ON_FINISH, onFinishHandler, false, 0, true);
+ }
+
+ // Create the mask for moogaloop
+ this.addChild(player_mask);
+ container.mask = player_mask;
+ this.addChild(container);
+
+ redrawMask();
+
+ load_timer.addEventListener(TimerEvent.TIMER, playerLoadedCheck);
+ load_timer.start();
+ }
+
+ /**
+ * Wait for Moogaloop to finish setting up
+ */
+ private function playerLoadedCheck(e:TimerEvent) : void
+ {
+ if (moogaloop.player_loaded)
+ {
+ // Moogaloop is finished configuring
+ load_timer.stop();
+ load_timer.removeEventListener(TimerEvent.TIMER, playerLoadedCheck);
+
+ // remove moogaloop's mouse listeners listener
+ moogaloop.disableMouseMove();
+ stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMove);
+
+ dispatchEvent(new Event(Event.COMPLETE));
+ }
+ }
+
+ /**
+ * Fake the mouse move/out events for Moogaloop
+ */
+ private function mouseMove(e:MouseEvent) : void
+ {
+ var pos : Point = this.parent.localToGlobal(new Point(this.x, this.y));
+ if (e.stageX >= pos.x && e.stageX <= pos.x + this.player_width &&
+ e.stageY >= pos.y && e.stageY <= pos.y + this.player_height)
+ {
+ moogaloop.mouseMove(e);
+ }
+ else
+ {
+ moogaloop.mouseOut();
+ }
+ }
+
+ private function redrawMask() : void
+ {
+ with (player_mask.graphics)
+ {
+ beginFill(0x000000, 1);
+ drawRect(container.x, container.y, player_width, player_height);
+ endFill();
+ }
+ }
+
+ public function play() : void
+ {
+ moogaloop.play();
+ }
+
+ public function pause() : void
+ {
+ moogaloop.pause();
+ }
+
+ /**
+ * returns duration of video in seconds
+ */
+ public function getDuration() : int
+ {
+ return moogaloop.duration;
+ }
+
+ /**
+ * Seek to specific loaded time in video (in seconds)
+ */
+ public function seekTo(time:int) : void
+ {
+ moogaloop.seek(time);
+ }
+
+ /**
+ * Change the primary color (i.e. 00ADEF)
+ */
+ public function changeColor(hex:String) : void
+ {
+ moogaloop.color = uint('0x' + hex);
+ }
+
+ /**
+ * Load in a different video
+ */
+ public function loadVideo(id:int) : void
+ {
+ moogaloop.loadVideo(id);
+ }
+
+ public function setSize(w:int, h:int) : void
+ {
+ this.setDimensions(w, h);
+
+ var size : Object = new Object();
+ size.width = w;
+ size.height = h;
+ moogaloop.size = size;
+
+ this.redrawMask();
+ }
+
+ /**
+ * API v2 Event Handlers
+ */
+ private function readyHandler(event:Event) : void
+ {
+ trace('readyHandler');
+ }
+
+ private function playHandler(event:Event) : void
+ {
+ trace('playHandler');
+ }
+
+ private function pauseHandler(event:Event) : void
+ {
+ trace('pauseHandler');
+ }
+
+ private function seekHandler(event:Event) : void
+ {
+ trace('seekHandler');
+ }
+
+ private function loadProgressHandler(event:Event) : void
+ {
+ trace('loadProgressHandler');
+ }
+
+ private function playProgressHandler(event:Event) : void
+ {
+ trace('playProgressHandler');
+ }
+
+ private function finishHandler(event:Event) : void
+ {
+ trace('finishHandler');
+ }
+
+ /**
+ * API v1 Event Handlers
+ */
+ private function onPlayHandler(event:Event) : void
+ {
+ trace('onPlayHandler');
+ }
+
+ private function onPauseHandler(event:Event) : void
+ {
+ trace('onPauseHandler');
+ }
+
+ private function onSeekHandler(event:Event) : void
+ {
+ trace('onSeekHandler');
+ }
+
+ private function onLoadingHandler(event:Event) : void
+ {
+ trace('onLoadingHandler');
+ }
+
+ private function onProgressHandler(event:Event) : void
+ {
+ trace('onProgressHandler');
+ }
+
+ private function onFinishHandler(event:Event) : void
+ {
+ trace('onFinishHandler');
+ }
+ }
+}
44 actionscript/src/com/vimeo/example/ExampleProject.as
@@ -0,0 +1,44 @@
+package com.vimeo.example
+{
+ import com.vimeo.api.VimeoPlayer;
+
+ import flash.display.Sprite;
+ import flash.display.StageAlign;
+ import flash.display.StageScaleMode;
+
+ /**
+ * Example Project
+ *
+ * An example of how to use the VimeoPlayer class within your Flash AS3 projects.
+ *
+ * @author Ryan Hefner <ryan@vimeo.com>
+ * @version $Id$
+ */
+ public class ExampleProject extends Sprite
+ {
+ // Elements
+ private var player : VimeoPlayer;
+
+
+ /**
+ * constructor
+ */
+ public function ExampleProject()
+ {
+ super();
+ init();
+ }
+
+ /**
+ * Initiate the ExampleProject.
+ */
+ public function init() : void
+ {
+ stage.align = StageAlign.TOP_LEFT;
+ stage.scaleMode = StageScaleMode.NO_SCALE;
+
+ player = new VimeoPlayer('XXXX', 2, 640, 360);
+ this.addChild(player);
+ }
+ }
+}
271 javascript/froogaloop.js
@@ -0,0 +1,271 @@
+// Init style shamelessly stolen from jQuery http://jquery.com
+alert('Remove this line before using in production!');
+var Froogaloop = (function(){
+
+ // Define a local copy of Froogaloop
+ function Froogaloop(iframe) {
+ // The Froogaloop object is actually just the init constructor
+ return new Froogaloop.fn.init(iframe);
+ }
+
+ var eventCallbacks = {},
+ hasWindowEvent = false,
+ slice = Array.prototype.slice;
+
+ Froogaloop.fn = Froogaloop.prototype = {
+ playerDomain: '',
+
+ element: null,
+
+ init: function(iframe) {
+ if (typeof iframe === "string") {
+ iframe = document.getElementById(iframe);
+ }
+
+ this.element = iframe;
+ return this;
+ },
+
+ /*
+ * Calls a function to act upon the player.
+ *
+ * @param {string} method The name of the Javascript API method to call. Eg: 'play'.
+ * @param {Array|Function} valueOrCallback params Array of parameters to pass when calling an API method
+ * or callback function when the method returns a value.
+ */
+ api: function(method, valueOrCallback) {
+ if (!this.element || !method) {
+ return false;
+ }
+
+ var self = this,
+ element = self.element,
+ target_id = element.id != '' ? element.id : null,
+ params = !isFunction(valueOrCallback) ? valueOrCallback : null,
+ callback = isFunction(valueOrCallback) ? valueOrCallback : null;
+
+ // Store the callback for get functions
+ if (callback) {
+ storeCallback(method, callback, target_id);
+ }
+
+ postMessage(method, params, element);
+ return self;
+ },
+
+ /*
+ * Registers an event listener and a callback function that gets called when the event fires.
+ *
+ * @param eventName (String): Name of the event to listen for.
+ * @param callback (Function): Function that should be called when the event fires.
+ */
+ addEvent: function(eventName, callback) {
+ if (!this.element) {
+ return false;
+ }
+
+ var self = this,
+ element = self.element,
+ target_id = element.id != '' ? element.id : null;
+
+
+ storeCallback(eventName, callback, target_id);
+
+ // The ready event is not registered via postMessage. It fires regardless.
+ if (eventName != 'ready') {
+ postMessage('addEventListener', eventName, element);
+ }
+
+ // Register message event listeners
+ if (hasWindowEvent) {
+ return self;
+ }
+
+ playerDomain = getDomainFromUrl(element.getAttribute('src'));
+
+ // Listens for the message event.
+ // W3C
+ if (window.addEventListener) {
+ window.addEventListener('message', onMessageReceived, false);
+ }
+ // IE
+ else {
+ window.attachEvent('onmessage', onMessageReceived, false);
+ }
+
+ hasWindowEvent = true;
+ return self;
+ },
+
+ /*
+ * Unregisters an event listener that gets called when the event fires.
+ *
+ * @param eventName (String): Name of the event to stop listening for.
+ */
+ removeEvent: function(eventName) {
+ if (!this.element) {
+ return false;
+ }
+
+ var self = this,
+ element = self.element,
+ target_id = element.id != '' ? element.id : null,
+ removed = removeCallback(eventName, target_id);
+
+ // The ready event is not registered
+ if (eventName != 'ready' && removed) {
+ postMessage('removeEventListener', eventName, element);
+ }
+ }
+ };
+
+ /**
+ * Handles posting a message to the parent window.
+ *
+ * @param method (String): name of the method to call inside the player. For api calls
+ * this is the name of the api method (api_play or api_pause) while for events this method
+ * is api_addEventListener.
+ * @param params (Object or Array): List of parameters to submit to the method. Can be either
+ * a single param or an array list of parameters.
+ * @param target (HTMLElement): Target iframe to post the message to.
+ */
+ function postMessage(method, params, target) {
+ if (!target.contentWindow.postMessage) {
+ return false;
+ }
+
+ var url = target.getAttribute('src').split('?')[0],
+ data = JSON.stringify({
+ method: method,
+ value: params
+ });
+
+ target.contentWindow.postMessage(data, url);
+ }
+
+ /**
+ * Event that fires whenever the window receives a message from its parent
+ * via window.postMessage.
+ */
+ function onMessageReceived(event) {
+ // Handles messages from moogaloop only
+ if (event.origin != playerDomain) {
+ return false;
+ }
+
+ var data = JSON.parse(event.data),
+ value = data.value,
+ method = data.event || data.method,
+ eventData = data.data,
+ target_id = target_id == '' ? null : data.player_id,
+
+ callback = getCallback(method, target_id),
+ params = [];
+
+ if (!callback) {
+ return false;
+ }
+
+ if (value !== undefined) {
+ params.push(value);
+ }
+
+ if (eventData) {
+ params.push(eventData);
+ }
+
+ if (target_id) {
+ params.push(target_id);
+ }
+
+ return params.length > 0 ? callback.apply(null, params) : callback.call();
+ }
+
+
+ /**
+ * Stores submitted callbacks for each iframe being tracked and each
+ * event for that iframe.
+ *
+ * @param eventName (String): Name of the event. Eg. api_onPlay
+ * @param callback (Function): Function that should get executed when the
+ * event is fired.
+ * @param target_id (String) [Optional]: If handling more than one iframe then
+ * it stores the different callbacks for different iframes based on the iframe's
+ * id.
+ */
+ function storeCallback(eventName, callback, target_id) {
+ if (target_id) {
+ if (!eventCallbacks[target_id]) {
+ eventCallbacks[target_id] = {};
+ }
+ eventCallbacks[target_id][eventName] = callback;
+ }
+ else {
+ eventCallbacks[eventName] = callback;
+ }
+ }
+
+ /**
+ * Retrieves stored callbacks.
+ */
+ function getCallback(eventName, target_id) {
+ if (target_id) {
+ return eventCallbacks[target_id][eventName];
+ }
+ else {
+ return eventCallbacks[eventName];
+ }
+ }
+
+ function removeCallback(eventName, target_id) {
+ if (target_id && eventCallbacks[target_id]) {
+ if (!eventCallbacks[target_id][eventName]) {
+ return false;
+ }
+ eventCallbacks[target_id][eventName] = null;
+ }
+ else {
+ if (!eventCallbacks[eventName]) {
+ return false;
+ }
+ eventCallbacks[eventName] = null;
+ }
+
+ return true;
+ }
+
+ /**
+ * Returns a domain's root domain.
+ * Eg. returns http://vimeo.com when http://vimeo.com/channels is sbumitted
+ *
+ * @param url (String): Url to test against.
+ * @return url (String): Root domain of submitted url
+ */
+ function getDomainFromUrl(url) {
+ var url_pieces = url.split('/'),
+ domain_str = '';
+
+ for(var i = 0, length = url_pieces.length; i < length; i++) {
+ if(i<3) {domain_str += url_pieces[i];}
+ else {break;}
+ if(i<2) {domain_str += '/';}
+ }
+
+ return domain_str;
+ }
+
+ function isFunction(obj) {
+ return !!(obj && obj.constructor && obj.call && obj.apply);
+ }
+
+ function isArray(obj) {
+ return toString.call(obj) === '[object Array]';
+ }
+
+ // Give the init function the Froogaloop prototype for later instantiation
+ Froogaloop.fn.init.prototype = Froogaloop.fn;
+
+ // Expose froogaloop to the global object
+ return (window.Froogaloop = window.$f = Froogaloop);
+
+})();
5 javascript/froogaloop.min.js
@@ -0,0 +1,5 @@
+alert('Remove this line before using in production!');
+var Froogaloop=function(){function g(a){return new g.fn.init(a)}function h(a,b,c){if(!c.contentWindow.postMessage)return!1;var f=c.getAttribute("src").split("?")[0];a=JSON.stringify({method:a,value:b});c.contentWindow.postMessage(a,f)}function i(a){if(a.origin!=playerDomain)return!1;var b=JSON.parse(a.data);a=b.value;var c=b.data,f=f==""?null:b.player_id;b=f?d[f][b.event||b.method]:d[b.event||b.method];var e=[];if(!b)return!1;a!==void 0&&e.push(a);c&&e.push(c);f&&e.push(f);return e.length>0?b.apply(null,
+e):b.call()}function j(a,b,c){c?(d[c]||(d[c]={}),d[c][a]=b):d[a]=b}var d={},k=!1;g.fn=g.prototype={playerDomain:"",element:null,init:function(a){typeof a==="string"&&(a=document.getElementById(a));this.element=a;return this},api:function(a,b){if(!this.element||!a)return!1;var c=this.element,f=c.id!=""?c.id:null,e=!b||!b.constructor||!b.call||!b.apply?b:null,d=b&&b.constructor&&b.call&&b.apply?b:null;d&&j(a,d,f);h(a,e,c);return this},addEvent:function(a,b){if(!this.element)return!1;var c=this.element;
+j(a,b,c.id!=""?c.id:null);a!="ready"&&h("addEventListener",a,c);if(k)return this;c=c.getAttribute("src").split("/");for(var d="",e=0,g=c.length;e<g;e++){if(e<3)d+=c[e];else break;e<2&&(d+="/")}playerDomain=d;window.addEventListener?window.addEventListener("message",i,!1):window.attachEvent("onmessage",i,!1);k=!0;return this},removeEvent:function(a){if(!this.element)return!1;var b=this.element,c;a:{if((c=b.id!=""?b.id:null)&&d[c]){if(!d[c][a]){c=!1;break a}d[c][a]=null}else{if(!d[a]){c=!1;break a}d[a]=
+null}c=!0}a!="ready"&&c&&h("removeEventListener",a,b)}};g.fn.init.prototype=g.fn;return window.Froogaloop=window.$f=g}();
612 javascript/playground.html
@@ -0,0 +1,612 @@
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ <meta name="viewport" content="width=700,maximum-scale=1.0,user-scalable=yes">
+ <title>Vimeo Froogaloop API Playground</title>
+ <style>
+ body, html, dl, dd { margin: 0; padding: 0;}
+
+ body, html {
+ font-family: "Helvetica Neue", Helvetica, Arial, Geneva, sans-serif;
+ color: #343434;
+ background: #f7f7f7;
+ }
+
+ iframe {
+ display:block;
+ border:0;
+ margin-bottom: 20px;
+ }
+
+ h1 {
+ font-weight: normal;
+ text-align: center;
+ }
+
+ button {
+ background: #e9e9e9;
+ cursor: pointer;
+ border: 1px solid #ddd;
+ padding: 2px 13px;
+ -webkit-border-radius: 3px;
+ -moz-border-radius: 3px;
+ margin: 0;
+ cursor: pointer;
+ }
+
+ .wrapper {
+ width: 600px;
+ margin: 0 auto;
+ margin-bottom: 30px;
+ }
+
+ .wrapper .container > div {
+ background: #fff;
+ padding: 30px;
+ border: 1px solid #ddd;
+ box-sizing: border-box;
+ margin-top: 30px;
+ }
+
+ .wrapper .container:first-child {
+ margin-top: 0;
+ }
+
+ .wrapper .container h2 {
+ margin: 0 0 20px 0;
+ }
+
+ .wrapper .container button {
+ line-height: 19px;
+ }
+
+ .wrapper .container input[type="text"] {
+ font-size: 12px;
+ }
+
+ button input[type="text"] {
+ border: 1px solid #ddd;
+ text-align: center;
+ -webkit-border-radius: 3px;
+ -moz-border-radius: 3px;
+ margin: 0 -11px 0 5px;
+ padding: 2px;
+ }
+
+ .wrapper div dl {
+ margin-bottom: 15px;
+ }
+
+ .wrapper div dt {
+ margin-bottom: 5px;
+ }
+
+ .wrapper div dt span {
+ font-size: 0.9em;
+ color: #666;
+ }
+
+ .wrapper div dd {
+ display: inline-block;
+ font-size: 12px;
+ margin-bottom: 5px;
+ }
+
+ .wrapper div dd label {
+ margin-right: 10px;
+ }
+
+ .wrapper div .output {
+ display: block;
+ width: 100%;
+ height: 100px;
+ border: 1px solid #ddd;
+ overflow-y: auto;
+ font-size: 13px;
+ padding: 5px;
+ box-sizing: border-box;
+ line-height: 1.4em;
+ resize: vertical;
+ font-family: Inconsolata, Monaco, monospace;
+ }
+
+ .wrapper .container > button {
+ border: 1px solid #ddd;
+ font-weight: bold;
+ font-size: 1.2em;
+ margin: -1px 0 0 0;
+ border-top-left-radius: 0;
+ border-top-right-radius: 0;
+ }
+
+ .wrapper > button input[type="text"] {
+ padding: 6px;
+ }
+
+ .console dd {
+ width: 100%;
+ white-space: nowrap;
+ }
+
+ .console .clear {
+ margin-top: 10px;
+ }
+ </style>
+ </head>
+ <body>
+ <div class="wrapper">
+ <hgroup>
+ <h1>Vimeo Froogaloop API Playground</h1>
+ </hgroup>
+ <div class="container">
+ <div>
+ <h2>Vimeo Player 1</h2>
+ <iframe id="player_1" src="http://player.vimeo.com/video/7100569?api=1&amp;player_id=player_1" width="540" height="304" frameborder="0"></iframe>
+ <dl class="simple">
+ <dt>Simple Buttons <span>(buttons with simple API calls)</span></dt>
+ <dd><button class="play">Play</button></dd>
+ <dd><button class="pause">Pause</button></dd>
+ <dd><button class="unload">Unload</button></dd>
+ </dl>
+ <dl class="modifiers">
+ <dt>Modifier Buttons <span>(buttons that modify the player)</span></dt>
+ <dd><button class="seek">Seek <input type="text" value="30" size="3" maxlength="3" /></button></dd>
+ <dd><button class="volume">Volume <input type="text" value="0.5" size="3" maxlength="3" /></button></dd>
+ <dd><button class="loop">Loop <input type="text" value="0" size="3" maxlength="3" /></button></dd>
+ <dd><button class="color">Color <input type="text" value="00adef" size="5" /></button></dd>
+ <dd><button class="randomColor">Random Color</button></dd>
+ </dl>
+ <dl class="getters">
+ <dt>Getters <span>(buttons that get back a value; logged out in the console)</span></dt>
+ <dd><button class="time">Current Time</button></dd>
+ <dd><button class="duration">Duration</button></dd>
+ <dd><button class="color">Color</button></dd>
+ <dd><button class="url">URL</button></dd>
+ <dd><button class="embed">Embed Code</button></dd>
+ <dd><button class="paused">Paused</button></dd>
+ <dd><button class="getVolume">Volume</button></dd>
+ <dd><button class="height">Video Height</button></dd>
+ <dd><button class="width">Video Width</button></dd>
+ </dl>
+ <dl class="listeners">
+ <dt>Event Listeners</dt>
+ <dd><label><input class="loadProgress" type="checkbox" checked />loadProgress</label></dd>
+ <dd><label><input class="playProgress" type="checkbox" checked />playProgress</label></dd>
+ <dd><label><input class="play" type="checkbox" checked />play</label></dd>
+ <dd><label><input class="pause" type="checkbox" checked />pause</label></dd>
+ <dd><label><input class="finish" type="checkbox" checked />finish</label></dd>
+ <dd><label><input class="seek" type="checkbox" checked />seek</label></dd>
+ </dl>
+ <dl class="console">
+ <dt>Console</dt>
+ <dd><textarea class="output" readonly="readonly"></textarea><button class="clear">Clear</button></dd>
+ </dl>
+ </div>
+ <button class="addClip" title="Add a new clip.">+ <input type="text" value="3718294" size="8" /></button>
+ </div>
+
+ <script src="froogaloop.js"></script>
+ <script>
+ (function(){
+
+ // Listen for the ready event for any vimeo video players on the page
+ var vimeoPlayers = document.querySelectorAll('iframe'),
+ player;
+
+ for (var i = 0, length = vimeoPlayers.length; i < length; i++) {
+ player = vimeoPlayers[i];
+ $f(player).addEvent('ready', ready);
+ }
+
+ /**
+ * Utility function for adding an event. Handles the inconsistencies
+ * between the W3C method for adding events (addEventListener) and
+ * IE's (attachEvent).
+ */
+ function addEvent(element, eventName, callback) {
+ if (element.addEventListener) {
+ element.addEventListener(eventName, callback, false);
+ }
+ else {
+ element.attachEvent(eventName, callback, false);
+ }
+ }
+
+ /**
+ * Called once a vimeo player is loaded and ready to receive
+ * commands. You can add events and make api calls only after this
+ * function has been called.
+ */
+ function ready(player_id) {
+ // Keep a reference to Froogaloop for this player
+ var container = document.getElementById(player_id).parentNode.parentNode,
+ froogaloop = $f(player_id),
+ apiConsole = container.querySelector('.console .output');
+
+ /**
+ * Prepends log messages to the example console for you to see.
+ */
+ function apiLog(message) {
+ apiConsole.innerHTML = message + '\n' + apiConsole.innerHTML;
+ }
+
+ /**
+ * Sets up the actions for the buttons that will perform simple
+ * api calls to Froogaloop (play, pause, etc.). These api methods
+ * are actions performed on the player that take no parameters and
+ * return no values.
+ */
+ function setupSimpleButtons() {
+ var buttons = container.querySelector('div dl.simple'),
+ playBtn = buttons.querySelector('.play'),
+ pauseBtn = buttons.querySelector('.pause'),
+ unloadBtn = buttons.querySelector('.unload');
+
+ // Call play when play button clicked
+ addEvent(playBtn, 'click', function() {
+ froogaloop.api('play');
+ }, false);
+
+ // Call pause when pause button clicked
+ addEvent(pauseBtn, 'click', function() {
+ froogaloop.api('pause');
+ }, false);
+
+ // Call unload when unload button clicked
+ addEvent(unloadBtn, 'click', function() {
+ froogaloop.api('unload');
+ }, false);
+ }
+
+ /**
+ * Sets up the actions for the buttons that will modify certain
+ * things about the player and the video in it. These methods
+ * take a parameter, such as a color value when setting a color.
+ */
+ function setupModifierButtons() {
+ var buttons = container.querySelector('div dl.modifiers'),
+ seekBtn = buttons.querySelector('.seek'),
+ volumeBtn = buttons.querySelector('.volume'),
+ loopBtn = buttons.querySelector('.loop'),
+ colorBtn = buttons.querySelector('.color'),
+ randomColorBtn = buttons.querySelector('.randomColor');
+
+ // Call seekTo when seek button clicked
+ addEvent(seekBtn, 'click', function(e) {
+ // Don't do anything if clicking on anything but the button (such as the input field)
+ if (e.target != this) {
+ return false;
+ }
+
+ // Grab the value in the input field
+ var seekVal = this.querySelector('input').value;
+
+ // Call the api via froogaloop
+ froogaloop.api('seekTo', seekVal);
+ }, false);
+
+ // Call setVolume when volume button clicked
+ addEvent(volumeBtn, 'click', function(e) {
+ // Don't do anything if clicking on anything but the button (such as the input field)
+ if (e.target != this) {
+ return false;
+ }
+
+ // Grab the value in the input field
+ var volumeVal = this.querySelector('input').value;
+
+ // Call the api via froogaloop
+ froogaloop.api('setVolume', volumeVal);
+ }, false);
+
+ // Call setLoop when loop button clicked
+ addEvent(loopBtn, 'click', function(e) {
+ // Don't do anything if clicking on anything but the button (such as the input field)
+ if (e.target != this) {
+ return false;
+ }
+
+ // Grab the value in the input field
+ var loopVal = this.querySelector('input').value;
+
+ //Call the api via froogaloop
+ froogaloop.api('setLoop', loopVal);
+ }, false);
+
+ // Call setColor when color button clicked
+ addEvent(colorBtn, 'click', function(e) {
+ // Don't do anything if clicking on anything but the button (such as the input field)
+ if (e.target != this) {
+ return false;
+ }
+
+ // Grab the value in the input field
+ var colorVal = this.querySelector('input').value;
+
+ // Call the api via froogaloop
+ froogaloop.api('setColor', colorVal);
+ }, false);
+
+ // Call setColor with a random color when random color button clicked
+ addEvent(randomColorBtn, 'click', function(e) {
+ // Don't do anything if clicking on anything but the button (such as the input field)
+ if (e.target != this) {
+ return false;
+ }
+
+ // Generate a random color
+ var colorVal = Math.floor(Math.random() * 16777215).toString(16);
+
+ // Call the api via froogaloop
+ froogaloop.api('setColor', colorVal);
+ }, false);
+ }
+
+ /**
+ * Sets up actions for buttons that will ask the player for something,
+ * such as the current time or duration. These methods require a
+ * callback function which will be called with any data as the first
+ * parameter in that function.
+ */
+ function setupGetterButtons() {
+ var buttons = container.querySelector('div dl.getters'),
+ timeBtn = buttons.querySelector('.time'),
+ durationBtn = buttons.querySelector('.duration'),
+ colorBtn = buttons.querySelector('.color'),
+ urlBtn = buttons.querySelector('.url'),
+ embedBtn = buttons.querySelector('.embed'),
+ pausedBtn = buttons.querySelector('.paused'),
+ getVolumeBtn = buttons.querySelector('.getVolume'),
+ widthBtn = buttons.querySelector('.width'),
+ heightBtn = buttons.querySelector('.height');
+
+ // Get the current time and log it to the API console when time button clicked
+ addEvent(timeBtn, 'click', function(e) {
+ froogaloop.api('getCurrentTime', function (value, player_id) {
+ // Log out the value in the API Console
+ apiLog('getCurrentTime : ' + value);
+ });
+ }, false);
+
+ // Get the duration and log it to the API console when time button clicked
+ addEvent(durationBtn, 'click', function(e) {
+ froogaloop.api('getDuration', function (value, player_id) {
+ // Log out the value in the API Console
+ apiLog('getDuration : ' + value);
+ });
+ }, false);
+
+ // Get the embed color and log it to the API console when time button clicked
+ addEvent(colorBtn, 'click', function(e) {
+ froogaloop.api('getColor', function (value, player_id) {
+ // Log out the value in the API Console
+ apiLog('getColor : ' + value);
+ });
+ }, false);
+
+ // Get the video url and log it to the API console when time button clicked
+ addEvent(urlBtn, 'click', function(e) {
+ froogaloop.api('getVideoUrl', function (value, player_id) {
+ // Log out the value in the API Console
+ apiLog('getVideoUrl : ' + value);
+ });
+ }, false);
+
+ // Get the embed code and log it to the API console when time button clicked
+ addEvent(embedBtn, 'click', function(e) {
+ froogaloop.api('getVideoEmbedCode', function (value, player_id) {
+ // Use html entities for less-than and greater-than signs
+ value = value.replace(/</g, '&lt;').replace(/>/g, '&gt;');
+
+ // Log out the value in the API Console
+ apiLog('getVideoEmbedCode : ' + value);
+ });
+ }, false);
+
+ // Get the paused state and log it to the API console when time button clicked
+ addEvent(pausedBtn, 'click', function(e) {
+ froogaloop.api('paused', function (value, player_id) {
+ // Log out the value in the API Console
+ apiLog('paused : ' + value);
+ });
+ }, false);
+
+ // Get the paused state and log it to the API console when time button clicked
+ addEvent(getVolumeBtn, 'click', function(e) {
+ froogaloop.api('getVolume', function (value, player_id) {
+ // Log out the value in the API Console
+ apiLog('volume : ' + value);
+ });
+ }, false);
+
+ // Get the paused state and log it to the API console when time button clicked
+ addEvent(widthBtn, 'click', function(e) {
+ froogaloop.api('getVideoWidth', function (value, player_id) {
+ // Log out the value in the API Console
+ apiLog('getVideoWidth : ' + value);
+ });
+ }, false);
+
+ // Get the paused state and log it to the API console when time button clicked
+ addEvent(heightBtn, 'click', function(e) {
+ froogaloop.api('getVideoHeight', function (value, player_id) {
+ // Log out the value in the API Console
+ apiLog('getVideoHeight : ' + value);
+ });
+ }, false);
+ }
+
+ /**
+ * Adds listeners for the events that are checked. Adding an event
+ * through Froogaloop requires the event name and the callback method
+ * that is called once the event fires.
+ */
+ function setupEventListeners() {
+ var checkboxes = container.querySelector('.listeners'),
+ loadProgressChk = checkboxes.querySelector('.loadProgress'),
+ playProgressChk = checkboxes.querySelector('.playProgress'),
+ playChk = checkboxes.querySelector('.play'),
+ pauseChk = checkboxes.querySelector('.pause'),
+ finishChk = checkboxes.querySelector('.finish'),
+ seekChk = checkboxes.querySelector('.seek');
+
+ function onLoadProgress() {
+ if (loadProgressChk.checked) {
+ froogaloop.addEvent('loadProgress', function(data) {
+ apiLog('loadProgress event : ' + data.percent + ' : ' + data.bytesLoaded + ' : ' + data.bytesTotal + ' : ' + data.duration);
+ });
+ }
+ else {
+ froogaloop.removeEvent('loadProgress');
+ }
+ }
+
+ function onPlayProgress() {
+ if (playProgressChk.checked) {
+ froogaloop.addEvent('playProgress', function(data) {
+ apiLog('playProgress event : ' + data.seconds + ' : ' + data.percent + ' : ' + data.duration);
+ });
+ }
+ else {
+ froogaloop.removeEvent('playProgress');
+ }
+ }
+
+ function onPlay() {
+ if (playChk.checked) {
+ froogaloop.addEvent('play', function(data) {
+ apiLog('play event');
+ });
+ }
+ else {
+ froogaloop.removeEvent('play');
+ }
+ }
+
+ function onPause() {
+ if (pauseChk.checked) {
+ froogaloop.addEvent('pause', function(data) {
+ apiLog('pause event');
+ });
+ }
+ else {
+ froogaloop.removeEvent('pause');
+ }
+ }
+
+ function onFinish() {
+ if (finishChk.checked) {
+ froogaloop.addEvent('finish', function(data) {
+ apiLog('finish');
+ });
+ }
+ else {
+ froogaloop.removeEvent('finish');
+ }
+ }
+
+ function onSeek() {
+ if (seekChk.checked) {
+ froogaloop.addEvent('seek', function(data) {
+ apiLog('seek event : ' + data.seconds + ' : ' + data.percent + ' : ' + data.duration);
+ });
+ }
+ else {
+ froogaloop.removeEvent('seek');
+ }
+ }
+
+ // Listens for the checkboxes to change
+ addEvent(loadProgressChk, 'change', onLoadProgress, false);
+ addEvent(playProgressChk, 'change', onPlayProgress, false);
+ addEvent(playChk, 'change', onPlay, false);
+ addEvent(pauseChk, 'change', onPause, false);
+ addEvent(finishChk, 'change', onFinish, false);
+ addEvent(seekChk, 'change', onSeek, false);
+
+ // Calls the change event if the option is checked
+ // (this makes sure the checked events get attached on page load as well as on changed)
+ onLoadProgress();
+ onPlayProgress();
+ onPlay();
+ onPause();
+ onFinish();
+ onSeek();
+ }
+
+ /**
+ * Sets up actions for adding a new clip window to the page.
+ */
+ function setupAddClip() {
+ var button = container.querySelector('.addClip'),
+ newContainer;
+
+ addEvent(button, 'click', function(e) {
+ // Don't do anything if clicking on anything but the button (such as the input field)
+ if (e.target != this) {
+ return false;
+ }
+
+ // Gets the index of the current player by simply grabbing the number after the underscore
+ var currentIndex = parseInt(player_id.split('_')[1]),
+ clipId = button.querySelector('input').value;
+
+ newContainer = resetContainer(container.cloneNode(true), currentIndex+1, clipId);
+
+ container.parentNode.appendChild(newContainer);
+ $f(newContainer.querySelector('iframe')).addEvent('ready', ready);
+ });
+
+ /**
+ * Resets the duplicate container's information, clearing out anything
+ * that doesn't pertain to the new clip. It also sets the iframe to
+ * use the new clip's id as its url.
+ */
+ function resetContainer(element, index, clipId) {
+ var newHeading = element.querySelector('h2'),
+ newIframe = element.querySelector('iframe'),
+ newCheckBoxes = element.querySelectorAll('.listeners input[type="checkbox"]'),
+ newApiConsole = element.querySelector('.console .output'),
+ newAddBtn = element.querySelector('.addClip');
+
+ // Set the heading text
+ newHeading.innerText = 'Vimeo Player ' + index;
+
+ // Set the correct source of the new clip id
+ newIframe.src = 'http://player.vimeo.com/video/' + clipId + '?api=1&player_id=player_' + index;
+ newIframe.id = 'player_' + index;
+
+ // Reset all the checkboxes for listeners to be checked on
+ for (var i = 0, length = newCheckBoxes.length, checkbox; i < length; i++) {
+ checkbox = newCheckBoxes[i];
+ checkbox.setAttribute('checked', 'checked');
+ }
+
+ // Clear out the API console
+ newApiConsole.innerHTML = '';
+
+ // Update the clip ID of the add clip button
+ newAddBtn.querySelector('input').setAttribute('value', clipId);
+
+ return element;
+ }
+ }
+
+ setupSimpleButtons();
+ setupModifierButtons();
+ setupGetterButtons();
+ setupEventListeners();
+ setupAddClip();
+
+ // Setup clear console button
+ var clearBtn = container.querySelector('.console button');
+ addEvent(clearBtn, 'click', function(e) {
+ apiConsole.innerHTML = '';
+ }, false);
+
+ apiLog(player_id + ' ready!');
+ }
+ })();
+ </script>
+ </body>
+</html>
13 javascript/readme
@@ -0,0 +1,13 @@
+Hi everyone!
+
+Included is our JavaScript library for using the API with our Universal Embed code.
+We suggest that you either host the JS file yourself, or link to our official hosted copy:
+
+http://a.vimeocdn.com/js/froogaloop2.min.js
+
+For more information on the JS API, see the documentation page:
+
+http://vimeo.com/api/docs/player-js
+
+Until we meet again!
+- Brad (3/25/2011)
5 readme.mdown
@@ -0,0 +1,5 @@
+# Vimeo Player API Examples
+
+These are some examples and helpful things for using the Vimeo Player in your projects.
+
+Included are both Flash and JavaScript examples.

0 comments on commit 860a8fd

Please sign in to comment.
Something went wrong with that request. Please try again.