Archive

Archive for January, 2010

The first 360|Flex

January 27th, 2010 Randy 3 comments

It was Ted Patrick’s fault. He dared to come to Edmonton in January and I was so impressed with his presentation at EFUG that I registered for the first 360Flex conference which was being held at EBay HQ in SJ. Never been there before. Didn’t know anyone there. Friend and fellow Edmontonian Grant Skinner was going (and presenting) and that gave me confidence that at least I would know someone there (as it turned out, he was quite busy with the Adobe peeps and I didn’t see him much).

Leading up to the conference the buzz on the 360Flex website was to sign up on Twitter. I signed up under the name of “brando”. Remember, this is February 2007. NO ONE knew what Twitter was. Seemed like a useless service to me but it gave me a bunch of new Flex-knowing friends and maybe it would help me connect with some people when I got there. Through twitter I met PolyGeek and told him I was going to hunt him down and say hi.

On the flight to San Jose I met another Edmontonian who was going to the conference: Victor Rubba. Great guy. Now I have another friend to hang out with at the conference.

The morning of the first day I walked from my hotel to EBay and in the main entrance and I couldn’t believe my eyes. Thousands of miles from home, feeling like I was not in Kansas anymore, a guy was standing there with an Edmonton Oilers jersey on. (turns out he was from Calgary, which is ironic to the extreme). I met Tom and John for the first time and they offered me Chocolate cake that Tom’s wife made (nice!). They asked me what my Twitter sig was. They said in unison “Ah, Brando”. While waiting for the keynote I was chatting with some guy who looked really familiar to me. I asked him where he was from and he said San Diego. I shrugged and walked away. Sorry, Josh Tynjala, I was out of touch.

After the first session I was getting Danny Patterson to sign his book on Design Patterns for me when I looked up and saw two smiling faces in front of me. Zach Graves and Aaron King were developers on the Y! Maps team. Because RunningMap.com makes good use of Yahoo! Maps, I was pretty active in the maps online group. I had told them I was coming to the event. They found me first. Now I knew I had someone to hang with. GREAT GUYS. Aaron even gave me his staff issued Y! backpack (at Max 2008 Allen Rabinovich asked me where I got it because they are exclusive to Y! employees).

The food was amazing considering what I paid for the event ($150). I phoned my wife while sitting on the green grass by the ponds of coy and she was extremely jealous. Back home it was -15C˚ with snow up your waist. While chatting with Grant and some other guys I did a double take. “Phillip Kerman?” His was the first Actionscript book I have ever read. Chris Cantrell. Can’t miss Mike Chambers. Victor introduced me to Peter McKiernan who showed up on day two with the same shirt as me. LOL. I did in fact find Dan “PolyGeek” Florio and introduce myself. I didn’t chat with him long because I had to run and pee. Er. RunPee.com.

The presentations were amazing. Ely Greenfield’s was my favourite. Deepa Subramaniam. Mike Chambers. They were all great. I went to a presentation on ANT and the speaker, Joe Berkovitz, asked the audience if they were not using version control. I raised my hand then looked behind me. I was the only one with my hand up. Heh. Still don’t. Just kidding. Maybe not.

Ok, this post has gone on too long already and I think you got the point. Sign up for 360|Flex, San Jose, you will meet a ton of people and have your head filled up until it explodes. It’s the best Flex conference out there so sign up!

Categories: Flash development Tags:

This OSMF has RobotLegs

January 17th, 2010 Randy 1 comment

For ActionScript 3 development I have just begun exploring the Open Source Media Framework (OSMF) and the MVC based framework called RobotLegs. What better way than to use them together? The best way to learn this stuff is to dive in and apply it to real solutions. PLEASE leave a comment if I have gone astray.

You can download the source code here (based on OSMF sprint 8 and RobotLegs 1.0.2).

Here is the working proof of concept with video served by Castfire.com:

video swf did not load


Project goals:

  1. Build a production ready video player
  2. Learn OSMF
  3. AS3 only compiled with mxmlc
  4. Keep things organized

1. Build a video player

This is a longer term goal. The video player presented here is only a proof of concept. Video on the web continues to evolve and now seems like a good time to re-factor some key video player projects to bring them up to date and address new requirements.

2. Learn OSMF

Strobe Open Source Media Framework is an Adobe initiative to bring some standards to video player development. I have been itching to get my hands dirty with this new framework to decide for myself if it is worth buying into.

Some may think it is inevitable that OMSF will be over-architechted and therefore full of bloat. I can't really answer that yet. But I can say that I REALLY like the convenience methods that come with the MediaPlayer class. This build is 90k which includes RobotLegs ... acceptable.

Sure, you can build a video player that comes in at 15k. However, as soon as you start adding modern day requirements (CDN services, advert engines, analytics, chapters, xml lists etc) things quickly get complicated. The promise of OSMF is that all these things can be integrated into your video using a plug-in architecture which will greatly ease the burden of development.

3. ActionScript 3 only

Every video player I have worked on to date (other than a few Flex experiments) have been made with Flash Professional which means they need to be compiled from the Flash IDE. Using Flash Builder to compile the application de-couples the workflow from the Flash IDE which makes possible all sorts of interesting ideas.

This does not preclude the use of Flash Professional made libraries that can be used for things like the control bar. After all, the Flash IDE is still really good at some things.

4. Keep things organized

I have made probably a dozen or so custom video players to date. When building one from scratch it does not take tong before it gets complicated: video players are the mothers of all things asynchronous. I have my own particular way of using design patterns and structure but have never took the time to think through a solid framework and ultimately my projects get big enough that they no longer feet like they are on solid ground.

Someone else has thought it through and this is where RobotLegs comes in. I have had a pretty good experience with Cairngorm over the last couple years but it requires the Flex framework. Dependency Injection seems to be the hot topic recently and I have read some good things about RobotLegs so I thought I would give it a try. This video tutorial from John Lindquist helped me to put together this first implementation.

The thought here is that there are other views to manage than just the video player and control bar. RobotLegs will help make these views and OSMF plugins manageable and modular.

Some code

Here are a few classes to show how video player events flow through RobotLegs to the DetailsView so that bytes loaded and playback time can get updated. Download the source for the full meal deal.

Actionscript:
  1. /**
  2. * author: Randy Troppmann January 17, 2010
  3. * http://www.randytroppmann.com
  4. *
  5. * Permission is hereby granted, free of charge, to any person
  6. * obtaining a copy of this software (the "Software"),
  7. * to use the Software without restriction,
  8. * including without limitation the rights to use,
  9. * copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the
  11. * Software is furnished to do so.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  14. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  15. * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  16. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  17. * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  18. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. **/
  22.  
  23. package org.osmf.experiments.view{
  24.     import flash.display.Sprite;
  25.     import flash.events.Event;
  26.     import org.osmf.media.URLResource;
  27.     import org.osmf.net.NetLoader;
  28.     import org.osmf.utils.URL;
  29.     import org.osmf.video.VideoElement;
  30.     import org.osmf.display.MediaPlayerSprite;
  31.     import org.osmf.events.*;
  32.     import org.osmf.experiments.controller.MediaPlayerEvent;
  33.     import flash.text.TextField;
  34.     import flash.events.MouseEvent;
  35.    
  36.     public class MediaPlayerView extends Sprite{
  37.        
  38.         public static const TEST_PROGRESSIVE_URL:String = "http://serve.castfire.com/s:pre_post_M9Ow2/video/50082/50082_2009-01-14-235108.flv";
  39.         protected var media:MediaPlayerSprite;
  40.         protected var totalBytes:Number;
  41.         protected var duration:Number;
  42.         protected var currentTime:Number;
  43.         protected var playButton:PlayButton;
  44.         protected var isPlaying:Boolean = false;
  45.        
  46.         public function MediaPlayerView(){
  47.             media = new MediaPlayerSprite();
  48.             media.setAvailableSize(320, 240);
  49.             media.mediaPlayer.autoPlay = false;
  50.             media.mediaPlayer.addEventListener(LoadEvent.BYTES_LOADED_CHANGE, onBytesLoadedChange, false, 0, true);
  51.             media.mediaPlayer.addEventListener(LoadEvent.BYTES_TOTAL_CHANGE, onBytesTotalChange, false, 0, true);         
  52.             media.mediaPlayer.addEventListener( TimeEvent.DURATION_CHANGE, onDurationChange, false, 0, true );
  53.             media.mediaPlayer.addEventListener(TimeEvent.CURRENT_TIME_CHANGE, onPlayheadChange, false, 0, true);
  54.             addChild(media);
  55.             //// ADD PLAY BUTTON
  56.             playButton = new PlayButton();
  57.             addChild(playButton);
  58.             playButton.x = playButton.y = 5;
  59.            
  60.             playButton.addEventListener(MouseEvent.CLICK, handlePlayClick, false, 0, true);
  61.            
  62.         }
  63.        
  64.         public function testProgressive():void{
  65.             media.element = new VideoElement(new NetLoader(), new URLResource(new URL(TEST_PROGRESSIVE_URL)));
  66.         }
  67.        
  68.         protected function handlePlayClick(evt:MouseEvent):void{
  69.             isPlaying = !isPlaying;
  70.             if (isPlaying){
  71.                 media.mediaPlayer.play();
  72.                 playButton.label.text = "pause";
  73.             }
  74.             else{
  75.                 media.mediaPlayer.pause();
  76.                 playButton.label.text = "play";
  77.             }
  78.         }
  79.        
  80.         //// OSMF event methods
  81.         protected function onBytesLoadedChange(evt:LoadEvent):void{
  82.             var mediaEvent:MediaPlayerEvent = new MediaPlayerEvent(MediaPlayerEvent.BYTES_LOADED_CHANGE);
  83.             mediaEvent.bytes = evt.bytes;
  84.             dispatchEvent(mediaEvent);   
  85.         }
  86.        
  87.         protected function onBytesTotalChange(evt:LoadEvent):void{
  88.             totalBytes = evt.bytes;
  89.             var mediaEvent:MediaPlayerEvent = new MediaPlayerEvent(MediaPlayerEvent.PLAYER_SENDS_SIZE_CHANGE);
  90.             mediaEvent.bytes = evt.bytes;
  91.             dispatchEvent(mediaEvent);
  92.         }
  93.        
  94.         protected function onDurationChange(evt:TimeEvent):void{
  95.             duration = evt.time;
  96.             var mediaEvent:MediaPlayerEvent = new MediaPlayerEvent(MediaPlayerEvent.PLAYER_SENDS_DURATION_CHANGE);
  97.             mediaEvent.time = evt.time;
  98.             dispatchEvent(mediaEvent);
  99.         }
  100.        
  101.         protected function onPlayheadChange(evt:TimeEvent):void{
  102.             currentTime = evt.time;
  103.             var mediaEvent:MediaPlayerEvent = new MediaPlayerEvent(MediaPlayerEvent.PLAYER_SENDS_PLAYHEAD_TIME_CHANGE);
  104.             mediaEvent.time = evt.time;
  105.             dispatchEvent(mediaEvent);
  106.         }
  107.        
  108.     }
  109. }

The MediaPlayerViewMediator class captures the events from MediaPlayerView which sets a property in the model.

Actionscript:
  1. package org.osmf.experiments.view{
  2.     import org.robotlegs.mvcs.Mediator;
  3.     import org.osmf.experiments.model.PlayerModel;
  4.     import org.osmf.events.TimeEvent;
  5.     import org.osmf.experiments.controller.MediaPlayerEvent;
  6.    
  7.     public class MediaPlayerViewMediator extends Mediator{
  8.         [Inject]
  9.         public var mediaPlayerView:MediaPlayerView;
  10.         [Inject]
  11.         public var model:PlayerModel;
  12.        
  13.         override public function onRegister():void{
  14.             mediaPlayerView.addEventListener(MediaPlayerEvent.PLAYER_SENDS_DURATION_CHANGE, handleDurationChange);     
  15.             mediaPlayerView.addEventListener(MediaPlayerEvent.PLAYER_SENDS_PLAYHEAD_TIME_CHANGE, handlePlayheadTimeChange);   
  16.             mediaPlayerView.addEventListener(MediaPlayerEvent.PLAYER_SENDS_SIZE_CHANGE, handleTotalBytesChange);           
  17.             mediaPlayerView.addEventListener(MediaPlayerEvent.BYTES_LOADED_CHANGE, handleBytesLoaded);     
  18.         }
  19.        
  20.         protected function handleDurationChange(p_evt:MediaPlayerEvent):void{
  21.             model.duration = p_evt.time;
  22.         }      
  23.        
  24.         protected function handlePlayheadTimeChange(p_evt:MediaPlayerEvent):void{
  25.             model.currentTime = p_evt.time;
  26.         }
  27.        
  28.         protected function handleTotalBytesChange(p_evt:MediaPlayerEvent):void{
  29.             model.totalBytes = p_evt.bytes;
  30.         }
  31.        
  32.         protected function handleBytesLoaded(p_evt:MediaPlayerEvent):void{
  33.             model.bytesLoaded = p_evt.bytes;
  34.         }
  35.     }
  36. }

The model extends the RobotLegs Actor class can use the RobotLegs dispatch() method so that the event can be listened for from anywhere within the RobotLegs ecosystem.

Actionscript:
  1. package org.osmf.experiments.model{
  2.     import org.robotlegs.mvcs.Actor;
  3.     import org.osmf.experiments.controller.MediaPlayerEvent;
  4.    
  5.     public class PlayerModel extends Actor{
  6.        
  7.         public var _totalBytes:Number;
  8.         public var _bytesLoaded:Number;
  9.         public var _duration:Number;
  10.         public var _currentTime:Number;
  11.        
  12.         public function PlayerModel(){
  13.         }
  14.        
  15.         public function get duration():Number{
  16.             return _duration;
  17.         }
  18.  
  19.         public function set duration(value:Number):void{
  20.             _duration = value;
  21.             var durationEvent:MediaPlayerEvent = new MediaPlayerEvent(MediaPlayerEvent.DURATION_CHANGE);
  22.             durationEvent.time = duration;
  23.             dispatch(durationEvent);
  24.         }      
  25.  
  26.         public function get currentTime():Number{
  27.             return _currentTime;
  28.         }
  29.  
  30.         public function set currentTime(value:Number):void{
  31.             _currentTime = value;         
  32.             var timeEvent:MediaPlayerEvent = new MediaPlayerEvent(MediaPlayerEvent.PLAYHEAD_TIME_CHANGE);
  33.             timeEvent.time = value;
  34.             dispatch(timeEvent);
  35.         }
  36.  
  37.         public function get totalBytes():Number{
  38.             return _totalBytes;
  39.         }
  40.  
  41.         public function set totalBytes(value:Number):void{
  42.             _totalBytes = value;       
  43.             var mediaEvent:MediaPlayerEvent = new MediaPlayerEvent(MediaPlayerEvent.SIZE_CHANGE);
  44.             mediaEvent.bytes = value;
  45.             dispatch(mediaEvent);
  46.         }
  47.  
  48.         public function get bytesLoaded():Number{
  49.             return _bytesLoaded;
  50.         }
  51.  
  52.         public function set bytesLoaded(value:Number):void{
  53.             _bytesLoaded = value;      
  54.             var mediaEvent:MediaPlayerEvent = new MediaPlayerEvent(MediaPlayerEvent.BYTES_LOADED_CHANGE);
  55.             mediaEvent.bytes = value;
  56.             dispatch(mediaEvent);
  57.         }
  58.     }
  59. }

In this experiment, DetailsViewMonitor listens for the events from the model. Since it is injected with the DetailsView instance, it can hit its property setters with new data.

Actionscript:
  1. package org.osmf.experiments.view{
  2.     import org.robotlegs.mvcs.Mediator;
  3.     import org.osmf.experiments.controller.MediaPlayerEvent;
  4.    
  5.     public class DetailsViewMediator extends Mediator   {
  6.        
  7.         [Inject]
  8.         public var detailsView:DetailsView;
  9.        
  10.         override public function onRegister():void{
  11.             eventMap.mapListener(eventDispatcher, MediaPlayerEvent.DURATION_CHANGE, onDurationChange);
  12.             eventMap.mapListener(eventDispatcher, MediaPlayerEvent.PLAYHEAD_TIME_CHANGE, onPlayheadTimeChange);
  13.             eventMap.mapListener(eventDispatcher, MediaPlayerEvent.SIZE_CHANGE, onTotalBytesChange);
  14.             eventMap.mapListener(eventDispatcher, MediaPlayerEvent.BYTES_LOADED_CHANGE, onBytesLoadedChange);
  15.         }
  16.        
  17.         //// EVENT handlers
  18.         protected function onDurationChange(evt:MediaPlayerEvent):void{
  19.             detailsView.duration = evt.time;
  20.         }   
  21.        
  22.         protected function onPlayheadTimeChange(evt:MediaPlayerEvent):void{
  23.             detailsView.currentTime = evt.time;
  24.         }
  25.        
  26.         protected function onTotalBytesChange(evt:MediaPlayerEvent):void{
  27.             detailsView.size = evt.bytes;
  28.         }
  29.        
  30.         protected function onBytesLoadedChange(evt:MediaPlayerEvent):void{
  31.             detailsView.bytesLoaded = evt.bytes;
  32.         }
  33.     }
  34. }

Conclusion

Reading framework documentation makes my eyes bleed. The only way I can really intrinsically understand how they fit into how I build applications is to use them. RobotLegs is a winner. I have not worked with OSMF enough to have an opinion one way or the other ... it has not reached a dot oh release yet.

Categories: Flash development Tags:
Download Full Movie Online Street Kings download movie Behind Enemy Lines II: Axis of Evil download movie The Station Agent download movie Sister Act 2: Back in the Habit download movie Reversible Errors download movie Retrograde download movie Sister Act download movie Radio download movie Prince Valiant download movie Play dead download movie Cry for help download movie Witchboard download movie Conan the barbarian download movie Fire down below download movie Dadnapped download movie Groundhog day download movie sites for free ringtones att cell ringtones classic crime ringtones mp3 ringtones for nextel Street Kings download movie Behind Enemy Lines II: Axis of Evil download movie The Station Agent download movie Sister Act 2: Back in the Habit download movie Reversible Errors download movie Retrograde download movie Sister Act download movie Radio download movie Prince Valiant download movie Iron Road download movie Beat Street download movie Dr T and the Women download movie Doubt download movie Catch and Release download movie Reach for Me download movie The Fourth Protocol download movie Adulthood download movie The Avengers download movie Hanger download movie Fighting Words download movie Satan's Playground download movie Affinity download movie Click download movie The Tender Hook download movie The Forbidden Kingdom download movie Blancaflor, la hija del diablo download movie Liberty Kid download movie The Virgin Suicides download movie Northfork download movie Mad Max download movie Toy Story download movie Cheerleader Camp download movie Lightning Bug download movie Takedown download movie Sky Captain and the World of Tomorrow download movie The Babe download movie