| 1 | /** |
|---|
| 2 | * Player that crunches through all media formats Flash can read. |
|---|
| 3 | **/ |
|---|
| 4 | package com.jeroenwijering.player { |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | import com.jeroenwijering.events.*; |
|---|
| 8 | import com.jeroenwijering.models.*; |
|---|
| 9 | import com.jeroenwijering.plugins.*; |
|---|
| 10 | import com.jeroenwijering.utils.Configger; |
|---|
| 11 | import com.jeroenwijering.utils.Logger; |
|---|
| 12 | |
|---|
| 13 | import flash.display.MovieClip; |
|---|
| 14 | import flash.events.Event; |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | public class Player extends MovieClip { |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | /** All configuration values. Change them to hard-code your preferences. **/ |
|---|
| 21 | public var config:Object = { |
|---|
| 22 | author:undefined, |
|---|
| 23 | date:undefined, |
|---|
| 24 | description:undefined, |
|---|
| 25 | duration:0, |
|---|
| 26 | file:undefined, |
|---|
| 27 | image:undefined, |
|---|
| 28 | link:undefined, |
|---|
| 29 | start:0, |
|---|
| 30 | streamer:undefined, |
|---|
| 31 | tags:undefined, |
|---|
| 32 | title:undefined, |
|---|
| 33 | type:undefined, |
|---|
| 34 | |
|---|
| 35 | backcolor:undefined, |
|---|
| 36 | frontcolor:undefined, |
|---|
| 37 | lightcolor:undefined, |
|---|
| 38 | screencolor:undefined, |
|---|
| 39 | |
|---|
| 40 | controlbar:'bottom', |
|---|
| 41 | dock:false, |
|---|
| 42 | height:300, |
|---|
| 43 | icons:true, |
|---|
| 44 | playlist:'none', |
|---|
| 45 | playlistsize:180, |
|---|
| 46 | skin:undefined, |
|---|
| 47 | width:400, |
|---|
| 48 | |
|---|
| 49 | autostart:false, |
|---|
| 50 | bufferlength:1, |
|---|
| 51 | displayclick:'play', |
|---|
| 52 | fullscreen:false, |
|---|
| 53 | item:0, |
|---|
| 54 | linktarget:'_blank', |
|---|
| 55 | logo:undefined, |
|---|
| 56 | mute:false, |
|---|
| 57 | repeat:'none', |
|---|
| 58 | resizing:true, |
|---|
| 59 | shuffle:false, |
|---|
| 60 | smoothing:true, |
|---|
| 61 | state:'IDLE', |
|---|
| 62 | stretching:'uniform', |
|---|
| 63 | volume:90, |
|---|
| 64 | |
|---|
| 65 | abouttext:"JW Player", |
|---|
| 66 | aboutlink:"http://www.longtailvideo.com/players/jw-flv-player/", |
|---|
| 67 | client:undefined, |
|---|
| 68 | debug:'none', |
|---|
| 69 | id:undefined, |
|---|
| 70 | plugins:undefined, |
|---|
| 71 | version:'4.6.247' |
|---|
| 72 | }; |
|---|
| 73 | /** Reference to all stage graphics. **/ |
|---|
| 74 | public var skin:MovieClip; |
|---|
| 75 | /** Reference to the View of the MVC cycle, defining all API calls. **/ |
|---|
| 76 | public var view:View; |
|---|
| 77 | /** Object that loads all configuration variables. **/ |
|---|
| 78 | protected var configger:Configger; |
|---|
| 79 | /** Object that load the skin and plugins. **/ |
|---|
| 80 | protected var sploader:SPLoader; |
|---|
| 81 | /** Reference to the Controller of the MVC cycle. **/ |
|---|
| 82 | protected var controller:Controller; |
|---|
| 83 | /** Reference to the model of the MVC cycle. **/ |
|---|
| 84 | protected var model:Model; |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | /** Constructor; hides player and waits until it is added to the stage. **/ |
|---|
| 88 | public function Player():void { |
|---|
| 89 | skin = this['player']; |
|---|
| 90 | for(var i:Number=0; i<skin.numChildren; i++) { |
|---|
| 91 | skin.getChildAt(i).visible = false; |
|---|
| 92 | } |
|---|
| 93 | // This event is useful for Flex, but not recognized by FP9.0.16 |
|---|
| 94 | try { |
|---|
| 95 | addEventListener(Event.ADDED_TO_STAGE,loadConfig); |
|---|
| 96 | } catch(err:Error) { loadConfig(); } |
|---|
| 97 | }; |
|---|
| 98 | |
|---|
| 99 | |
|---|
| 100 | /** When added to stage, the player loads configuration settings. **/ |
|---|
| 101 | protected function loadConfig(evt:Event=null):void { |
|---|
| 102 | try { |
|---|
| 103 | removeEventListener(Event.ADDED_TO_STAGE,loadConfig); |
|---|
| 104 | } catch(err:Error) {} |
|---|
| 105 | configger = new Configger(this); |
|---|
| 106 | configger.addEventListener(Event.COMPLETE,loadSkin); |
|---|
| 107 | configger.load(config); |
|---|
| 108 | }; |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | /** When config is loaded, the player laods the skin. **/ |
|---|
| 112 | protected function loadSkin(evt:Event=null):void { |
|---|
| 113 | if(config['tracecall']) { |
|---|
| 114 | Logger.output = config['tracecall']; |
|---|
| 115 | } else { |
|---|
| 116 | Logger.output = config['debug']; |
|---|
| 117 | } |
|---|
| 118 | sploader = new SPLoader(this); |
|---|
| 119 | sploader.addEventListener(SPLoaderEvent.SKIN,loadMVC); |
|---|
| 120 | sploader.loadSkin(); |
|---|
| 121 | }; |
|---|
| 122 | |
|---|
| 123 | |
|---|
| 124 | /** When the skin is loaded, the model/view/controller are inited. **/ |
|---|
| 125 | protected function loadMVC(evt:SPLoaderEvent=null):void { |
|---|
| 126 | controller = new Controller(config,skin,sploader); |
|---|
| 127 | model = new Model(config,skin,sploader,controller); |
|---|
| 128 | view = new View(config,skin,sploader,controller,model); |
|---|
| 129 | controller.closeMVC(model,view); |
|---|
| 130 | addModels(); |
|---|
| 131 | addPlugins(); |
|---|
| 132 | sploader.addEventListener(SPLoaderEvent.PLUGINS,startPlayer); |
|---|
| 133 | sploader.loadPlugins(); |
|---|
| 134 | }; |
|---|
| 135 | |
|---|
| 136 | |
|---|
| 137 | /** Initialize all playback models. **/ |
|---|
| 138 | protected function addModels():void { |
|---|
| 139 | model.addModel(new HTTPModel(model),'http'); |
|---|
| 140 | model.addModel(new ImageModel(model),'image'); |
|---|
| 141 | model.addModel(new RTMPModel(model),'rtmp'); |
|---|
| 142 | model.addModel(new SoundModel(model),'sound'); |
|---|
| 143 | model.addModel(new VideoModel(model),'video'); |
|---|
| 144 | model.addModel(new YoutubeModel(model),'youtube'); |
|---|
| 145 | |
|---|
| 146 | model.addModel(new BitgravityModel(model),'bitgravity'); |
|---|
| 147 | model.addModel(new EdgeCastModel(model),'edgecast'); |
|---|
| 148 | model.addModel(new FCSubscribeModel(model),'fcsubscribe'); |
|---|
| 149 | model.addModel(new FLVSeekModel(model),'flvseek'); |
|---|
| 150 | model.addModel(new HighwindsModel(model),'highwinds'); |
|---|
| 151 | model.addModel(new LighttpdModel(model),'lighttpd'); |
|---|
| 152 | model.addModel(new VDOXModel(model),'vdox'); |
|---|
| 153 | }; |
|---|
| 154 | |
|---|
| 155 | |
|---|
| 156 | /** Init built-in plugins and load external ones. **/ |
|---|
| 157 | protected function addPlugins():void { |
|---|
| 158 | sploader.addPlugin(new Display(),'display'); |
|---|
| 159 | sploader.addPlugin(new Rightclick(),'rightclick'); |
|---|
| 160 | sploader.addPlugin(new Controlbar(),'controlbar'); |
|---|
| 161 | sploader.addPlugin(new Playlist(),'playlist'); |
|---|
| 162 | sploader.addPlugin(new Dock(),'dock'); |
|---|
| 163 | sploader.addPlugin(new Watermark(),'watermark'); |
|---|
| 164 | }; |
|---|
| 165 | |
|---|
| 166 | |
|---|
| 167 | /** |
|---|
| 168 | * Everything is now ready. The Player is redrawn, shown and the file is loaded. |
|---|
| 169 | * |
|---|
| 170 | * The Player broadcasts a READY event here to actionscript. |
|---|
| 171 | * The View will send an asynchroneous PlayerReady event to javascript. |
|---|
| 172 | **/ |
|---|
| 173 | protected function startPlayer(evt:SPLoaderEvent=null) { |
|---|
| 174 | view.sendEvent(ViewEvent.REDRAW); |
|---|
| 175 | dispatchEvent(new PlayerEvent(PlayerEvent.READY)); |
|---|
| 176 | view.playerReady(); |
|---|
| 177 | if(config['file']) { |
|---|
| 178 | view.sendEvent(ViewEvent.LOAD,config); |
|---|
| 179 | } |
|---|
| 180 | }; |
|---|
| 181 | |
|---|
| 182 | |
|---|
| 183 | } |
|---|
| 184 | |
|---|
| 185 | |
|---|
| 186 | } |
|---|