| 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.*; |
|---|
| 11 | |
|---|
| 12 | import flash.display.*; |
|---|
| 13 | import flash.events.*; |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | public class Player extends MovieClip { |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | /** All configuration values. Change them to hard-code your preferences. **/ |
|---|
| 20 | public var config:Object = { |
|---|
| 21 | author:undefined, |
|---|
| 22 | date:undefined, |
|---|
| 23 | description:undefined, |
|---|
| 24 | duration:0, |
|---|
| 25 | file:undefined, |
|---|
| 26 | image:undefined, |
|---|
| 27 | link:undefined, |
|---|
| 28 | start:0, |
|---|
| 29 | streamer:undefined, |
|---|
| 30 | tags:undefined, |
|---|
| 31 | title:undefined, |
|---|
| 32 | type:undefined, |
|---|
| 33 | |
|---|
| 34 | backcolor:undefined, |
|---|
| 35 | frontcolor:undefined, |
|---|
| 36 | lightcolor:undefined, |
|---|
| 37 | screencolor:undefined, |
|---|
| 38 | |
|---|
| 39 | controlbar:'bottom', |
|---|
| 40 | dock:false, |
|---|
| 41 | height:300, |
|---|
| 42 | icons:true, |
|---|
| 43 | playlist:'none', |
|---|
| 44 | playlistsize:180, |
|---|
| 45 | skin:undefined, |
|---|
| 46 | width:400, |
|---|
| 47 | |
|---|
| 48 | autostart:false, |
|---|
| 49 | bandwidth:5000, |
|---|
| 50 | bufferlength:1, |
|---|
| 51 | displayclick:'play', |
|---|
| 52 | fullscreen:false, |
|---|
| 53 | item:0, |
|---|
| 54 | level:0, |
|---|
| 55 | linktarget:'_blank', |
|---|
| 56 | logo:undefined, |
|---|
| 57 | mute:false, |
|---|
| 58 | repeat:'none', |
|---|
| 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.525' |
|---|
| 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 | visible = false; |
|---|
| 90 | skin = this['player']; |
|---|
| 91 | loadConfig(); |
|---|
| 92 | }; |
|---|
| 93 | |
|---|
| 94 | |
|---|
| 95 | /** When the skinis loaded, the config is loaded. **/ |
|---|
| 96 | protected function loadConfig():void { |
|---|
| 97 | configger = new Configger(this); |
|---|
| 98 | configger.addEventListener(Event.COMPLETE,loadSkin); |
|---|
| 99 | configger.load(config); |
|---|
| 100 | }; |
|---|
| 101 | |
|---|
| 102 | /** When config is loaded, the player laods the skin. **/ |
|---|
| 103 | protected function loadSkin(evt:Event):void { |
|---|
| 104 | if(config['tracecall']) { |
|---|
| 105 | Logger.output = config['tracecall']; |
|---|
| 106 | } else { |
|---|
| 107 | Logger.output = config['debug']; |
|---|
| 108 | } |
|---|
| 109 | sploader = new SPLoader(this); |
|---|
| 110 | sploader.addEventListener(SPLoaderEvent.SKIN,loadMVC); |
|---|
| 111 | sploader.loadSkin(); |
|---|
| 112 | }; |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | /** When the skin is loaded, the model/view/controller are inited. **/ |
|---|
| 116 | protected function loadMVC(evt:SPLoaderEvent):void { |
|---|
| 117 | controller = new Controller(config,skin,sploader); |
|---|
| 118 | model = new Model(config,skin,sploader,controller); |
|---|
| 119 | view = new View(config,skin,sploader,controller,model); |
|---|
| 120 | controller.closeMVC(model,view); |
|---|
| 121 | addModels(); |
|---|
| 122 | addPlugins(); |
|---|
| 123 | sploader.addEventListener(SPLoaderEvent.PLUGINS,startPlayer); |
|---|
| 124 | sploader.loadPlugins(); |
|---|
| 125 | }; |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | /** Initialize all playback models. **/ |
|---|
| 129 | protected function addModels():void { |
|---|
| 130 | model.addModel(new HTTPModel(model),'http'); |
|---|
| 131 | model.addModel(new ImageModel(model),'image'); |
|---|
| 132 | model.addModel(new LivestreamModel(model),'livestream'); |
|---|
| 133 | model.addModel(new RTMPModel(model),'rtmp'); |
|---|
| 134 | model.addModel(new SoundModel(model),'sound'); |
|---|
| 135 | model.addModel(new VideoModel(model),'video'); |
|---|
| 136 | model.addModel(new YoutubeModel(model),'youtube'); |
|---|
| 137 | }; |
|---|
| 138 | |
|---|
| 139 | |
|---|
| 140 | /** Init built-in plugins and load external ones. **/ |
|---|
| 141 | protected function addPlugins():void { |
|---|
| 142 | sploader.addPlugin(new Display(),'display'); |
|---|
| 143 | sploader.addPlugin(new Rightclick(),'rightclick'); |
|---|
| 144 | sploader.addPlugin(new Controlbar(),'controlbar'); |
|---|
| 145 | sploader.addPlugin(new Playlist(),'playlist'); |
|---|
| 146 | sploader.addPlugin(new Dock(),'dock'); |
|---|
| 147 | sploader.addPlugin(new Watermark(false),'watermark'); |
|---|
| 148 | }; |
|---|
| 149 | |
|---|
| 150 | |
|---|
| 151 | /** |
|---|
| 152 | * Everything is now ready. The Player is redrawn, shown and the file is loaded. |
|---|
| 153 | * |
|---|
| 154 | * The Player broadcasts a READY event here to actionscript. |
|---|
| 155 | * The View will send an asynchroneous PlayerReady event to javascript. |
|---|
| 156 | **/ |
|---|
| 157 | protected function startPlayer(evt:SPLoaderEvent):void { |
|---|
| 158 | view.sendEvent(ViewEvent.REDRAW); |
|---|
| 159 | visible = true; |
|---|
| 160 | dispatchEvent(new PlayerEvent(PlayerEvent.READY)); |
|---|
| 161 | view.playerReady(); |
|---|
| 162 | if(config['file']) { |
|---|
| 163 | view.sendEvent(ViewEvent.LOAD,config); |
|---|
| 164 | } |
|---|
| 165 | }; |
|---|
| 166 | |
|---|
| 167 | |
|---|
| 168 | } |
|---|
| 169 | |
|---|
| 170 | |
|---|
| 171 | } |
|---|