I am working on a project that is going to have an API that allows the user to insert video. The API is basically an ActionScript class that attaches a property when the user publishes their SWF. When the SWF is loaded into the main SWF program, it has access to the special functions in the SWF file. First, I just used the FLVPlayback and a registry function so the app would have access to it’s functions. That’s fine, but the user has to host an FLV for this to be effective. Not everyone has a server at their disposal, so this is the reason to build on existing video sites. Also, your not shit as a dev guy unless your mashable Web 2.0 savvy.
Fortunately, the popular sites have APIs out there ready and available to get content and media. A developer is expected to know what they have available to them and what will make the job easier for them. Being in the know about Facebook shit is actually a job requirement.
So, first one I thought of was the giant, YouTube. YouTube’s player is AS2 and to use it in an AS3 project you need to wrap it in an AS3 SWF and use LocalConnection to interface with it. There are a few solutions out there but in the end it is a band aid, until YouTube puts together an alternative player API. After fumbling with this, and saving the failing code to my repository for later, I went to Vimeo.
Vimeo has a pretty cool player and the thing that puts it over the top for my app is that it is written in ActionScript 3. But, as with everything, it isn’t perfect. YouTube has a good API page, and some decent forums, and support of the widespread dev community. Vimeo does not. Their API page is nothing short of pathetic, to say the least. They have one example and it doesn’t work. I found a working example on their fourm. At the top of the API page (as of this posting) they have a blurb that says this: You may have noticed that there are some inaccuracies in this documentation. We working on improving it. How about now? In the time it took to put up that asinine message you could of updated the code. That is annoying. Also, there is no public functions to be seen what so ever. Searching on the forums, someone found play, load and unload, which kind of works like stop. I also needed an event at the end of the video. Pretty standard stuff as far as a video API goes. Looks like I am going to have to Sherlock Holmes this shit.
There are some API functions exposed that I found by debugging the player. Use these at your own risk as they are not documented and may change. The way I figure it as soon there is an update to the player changing the functions to the real deal functions is no biggie. For the here and now I need ways to respond to the end of a video, play, pause and stop.
It seems that all the API commands are prefaced with api_ before the function name. Below are a list of functions that seem to be exposed for API usage. I have not tested all of them, but for what it’s worth here is a list. Some need parameters to work and my debugger isn’t specific about the datatype for these. So, here are the method signatures as far as I can tell. The debugger shows the wildcard (*) for datatypes that are not top level, so it could be anything specific to the Vimeo player. Really unknown unknowns are marked with a question mark.
function api_changeColor(?):? function api_changeOutro(one:String, two:*):void function api_disableHDEmbed():void function api_enableHDEmbed():* function api_isLoaded():Boolean function api_isPaused():Boolean function api_isPlaying():Boolean function api_likeClip():void function api_loadVideo(one:int):void function api_pause():* function api_play():* function api_seekTo(?):? function api_setOnFinishCallback(one:String):void function api_setOnPauseCallback(one:String):void function api_setOnProgressCallback(one:String):void function api_setSize(one:int, two:int):void function api_toggleElement(one:String, two:*):* function api_toggleFullscreen():void function api_toggleLoop():void function api_togglePlayPause(one:Boolean):void function api_unload():void function api_unload_other_players():*
For the api_setOn functions, they are callbacks for JavaScript, which means you will need a JavaScript function named the same as the parameter you pass in. Remember to set your HTML page param allowScriptAccess to always as this is coming from the Vimeo site otherwise you will get a SecurityError. I hope when they do get out the official API they will have an ActionScript event to respond to so I don’t have to shoot back and forth between AS and JS to do a simple thing like get the end of a video.
17 Responses
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.
Thanks heaps Robert, great bandaid.
Vimeo have to pick up the slack pretty soon in my mind
An example would be bang up!
Denis, in the post there is a link to a working example that idFlood posted in the Vimeo forums. It’s where I got the idea to look deeper into what the player was capable of. He uses some of the API calls in his code. So, take a look at this. It is a good place to start.
http://www.idflood.com/vimeo.txt
thanks for sharing! I still dont understand, why vimeo doensnt officially document their api though…
Stefan, I think they put a lot of time into their data APIs which is holding the Moogaloop API back. It is frustrating, especially when the API is already there just below the surface.
I also found out, the integration of the Moogaloop player into a flash file is buggy, once you place the player anywhere else than x:0/y:0 on stage: the activation rectangle showing the player interface (once you roll over while playback) will always stay fixed to 0:0.
Stefan, that does explain why the rollover doesn’t seem to work all the time. I thought that it might be something on my end. I believe I read about that bug in one of the Vimeo forums, but I didn’t make the connection until now. I’m not working on the video API for my project right now, but if I find a way to fix this in the future I’ll write a post about it. Feel free to tell me about it if you find a solution first!
Just wanted to let everyone know that we are officially offering the Moogaloop API now.
http://www.vimeo.com/api/docs/moogaloop
Thanks for the update Brad, but this doesn’t really apply to my post. Vimeo has indeed updated their API, but Vimeo only released the JavaScript API officially. The ActionScript API is still shrouded in the shadows. In Vimeo’s documentation, JS API is now top billing and AS API still has that ominous reminder that some of the documentation is not accurate. I did a short test (I will do some more later) to see if the AS API is still intact and it seems that the information above is still accurate. I’m glad to see that there is some motion on the Moogaloop front and I anxiously await the official release of the ActionScript API.
I have the same problem with the hit test zone, stuck in the top left of my swf. They seem to use the stage mouse position (not the parent container mouse position or the classics MouseOver/MouseOut events) …
If someone have a solution please post it here !
I tried to use the Moogaloop SWF in an AIR application but unfortunately I got a Security Error. The command Security.allowDomain(“http://bitcast.vimeo.com”); doesn’t work in an Air App. Do you or anybody know a workaround for this?
Thanks a lot!
We officially added AS API, but we’re still working on fully documenting it. The example class should provide a good start: http://www.vimeo.com/api/docs/moogaloop
This is great news, Casey! I see there are some API calls in the example that I found, so I guess the function names won’t be changing in the future. That is a relief. Thanks to the whole Vimeo team for keeping me informed.
I also worked with this Flash moogaloop API and I extended the vimeo Flash Class in the documentation. You can see my results on my blog:
http://blog.derhess.de/2009/08/12/working-with-vimeo-moogaloop-api-in-flash/
The AS api is tremendously buggy. That may explain why they don’t release it: 90% of the things they would have to document actually don’t work.
Continuing the Discussion