| 1 | package com.longtailvideo.jwplayer.player { |
|---|
| 2 | import com.longtailvideo.jwplayer.controller.Controller; |
|---|
| 3 | import com.longtailvideo.jwplayer.events.PlayerEvent; |
|---|
| 4 | import com.longtailvideo.jwplayer.model.IPlaylist; |
|---|
| 5 | import com.longtailvideo.jwplayer.model.Model; |
|---|
| 6 | import com.longtailvideo.jwplayer.model.PlayerConfig; |
|---|
| 7 | import com.longtailvideo.jwplayer.plugins.IPlugin; |
|---|
| 8 | import com.longtailvideo.jwplayer.utils.Logger; |
|---|
| 9 | import com.longtailvideo.jwplayer.utils.RootReference; |
|---|
| 10 | import com.longtailvideo.jwplayer.view.IPlayerComponents; |
|---|
| 11 | import com.longtailvideo.jwplayer.view.View; |
|---|
| 12 | import com.longtailvideo.jwplayer.view.interfaces.IPlayerComponent; |
|---|
| 13 | import com.longtailvideo.jwplayer.view.interfaces.ISkin; |
|---|
| 14 | |
|---|
| 15 | import flash.display.Sprite; |
|---|
| 16 | import flash.events.Event; |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | /** |
|---|
| 20 | * Sent when the player has been initialized and skins and plugins have been successfully loaded. |
|---|
| 21 | * |
|---|
| 22 | * @eventType com.longtailvideo.jwplayer.events.PlayerEvent.JWPLAYER_READY |
|---|
| 23 | */ |
|---|
| 24 | [Event(name="jwplayerReady", type="com.longtailvideo.jwplayer.events.PlayerEvent")] |
|---|
| 25 | /** |
|---|
| 26 | * Main class for JW Flash Media Player |
|---|
| 27 | * |
|---|
| 28 | * @author Pablo Schklowsky |
|---|
| 29 | */ |
|---|
| 30 | public class Player extends Sprite implements IPlayer { |
|---|
| 31 | protected static var _commercial:Boolean = Boolean(CONFIG::commercial); |
|---|
| 32 | |
|---|
| 33 | private var model:Model; |
|---|
| 34 | private var view:View; |
|---|
| 35 | private var controller:Controller; |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | /** Player constructor **/ |
|---|
| 39 | public function Player() { |
|---|
| 40 | new RootReference(this); |
|---|
| 41 | try { |
|---|
| 42 | this.addEventListener(Event.ADDED_TO_STAGE, setupPlayer); |
|---|
| 43 | } catch (err:Error) { |
|---|
| 44 | setupPlayer(); |
|---|
| 45 | } |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | private function setupPlayer(event:Event = null):void { |
|---|
| 50 | try { |
|---|
| 51 | this.removeEventListener(Event.ADDED_TO_STAGE, setupPlayer); |
|---|
| 52 | } catch (err:Error) { |
|---|
| 53 | } |
|---|
| 54 | model = new Model(); |
|---|
| 55 | view = new View(this, model); |
|---|
| 56 | controller = new Controller(this, model, view); |
|---|
| 57 | controller.addEventListener(PlayerEvent.JWPLAYER_READY, playerReady); |
|---|
| 58 | controller.setupPlayer(); |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | protected function playerReady(evt:PlayerEvent):void { |
|---|
| 63 | // Only handle JWPLAYER_READY once |
|---|
| 64 | controller.removeEventListener(PlayerEvent.JWPLAYER_READY, playerReady); |
|---|
| 65 | var jsAPI:JavascriptAPI = new JavascriptAPI(this); |
|---|
| 66 | model.addGlobalListener(forward); |
|---|
| 67 | view.addGlobalListener(forward); |
|---|
| 68 | controller.addGlobalListener(forward); |
|---|
| 69 | forward(evt); |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | /** |
|---|
| 74 | * Forwards all MVC events to interested listeners. |
|---|
| 75 | * @param evt |
|---|
| 76 | */ |
|---|
| 77 | protected function forward(evt:PlayerEvent):void { |
|---|
| 78 | Logger.log(evt.toString(), evt.type); |
|---|
| 79 | dispatchEvent(evt); |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | /** |
|---|
| 84 | * @inheritDoc |
|---|
| 85 | */ |
|---|
| 86 | public function get config():PlayerConfig { |
|---|
| 87 | return model.config; |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | /** |
|---|
| 92 | * @inheritDoc |
|---|
| 93 | */ |
|---|
| 94 | public function get version():String { |
|---|
| 95 | return PlayerVersion.version; |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | |
|---|
| 99 | /** |
|---|
| 100 | * @inheritDoc |
|---|
| 101 | */ |
|---|
| 102 | public function get commercial():Boolean { |
|---|
| 103 | return _commercial; |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | /** |
|---|
| 108 | * @inheritDoc |
|---|
| 109 | */ |
|---|
| 110 | public function get skin():ISkin { |
|---|
| 111 | return view.skin; |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | /** |
|---|
| 116 | * @inheritDoc |
|---|
| 117 | */ |
|---|
| 118 | public function get state():String { |
|---|
| 119 | return model.state; |
|---|
| 120 | } |
|---|
| 121 | |
|---|
| 122 | |
|---|
| 123 | /** |
|---|
| 124 | * @inheritDoc |
|---|
| 125 | */ |
|---|
| 126 | public function get playlist():IPlaylist { |
|---|
| 127 | return model.playlist; |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | |
|---|
| 131 | /** |
|---|
| 132 | * @inheritDoc |
|---|
| 133 | */ |
|---|
| 134 | public function get locked():Boolean { |
|---|
| 135 | return controller.locking; |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | |
|---|
| 139 | /** |
|---|
| 140 | * @inheritDoc |
|---|
| 141 | */ |
|---|
| 142 | public function lock(target:IPlugin, callback:Function):void { |
|---|
| 143 | controller.lockPlayback(target, callback); |
|---|
| 144 | } |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | /** |
|---|
| 148 | * @inheritDoc |
|---|
| 149 | */ |
|---|
| 150 | public function unlock(target:IPlugin):Boolean { |
|---|
| 151 | return controller.unlockPlayback(target); |
|---|
| 152 | } |
|---|
| 153 | |
|---|
| 154 | |
|---|
| 155 | /** |
|---|
| 156 | * @inheritDoc |
|---|
| 157 | */ |
|---|
| 158 | public function volume(volume:Number):Boolean { |
|---|
| 159 | return controller.setVolume(volume); |
|---|
| 160 | } |
|---|
| 161 | |
|---|
| 162 | |
|---|
| 163 | /** |
|---|
| 164 | * @inheritDoc |
|---|
| 165 | */ |
|---|
| 166 | public function get mute():Boolean { |
|---|
| 167 | return model.mute; |
|---|
| 168 | } |
|---|
| 169 | |
|---|
| 170 | |
|---|
| 171 | /** |
|---|
| 172 | * @inheritDoc |
|---|
| 173 | */ |
|---|
| 174 | public function set mute(state:Boolean):void { |
|---|
| 175 | controller.mute(state); |
|---|
| 176 | } |
|---|
| 177 | |
|---|
| 178 | |
|---|
| 179 | /** |
|---|
| 180 | * @inheritDoc |
|---|
| 181 | */ |
|---|
| 182 | public function play():Boolean { |
|---|
| 183 | return controller.play(); |
|---|
| 184 | } |
|---|
| 185 | |
|---|
| 186 | |
|---|
| 187 | /** |
|---|
| 188 | * @inheritDoc |
|---|
| 189 | */ |
|---|
| 190 | public function pause():Boolean { |
|---|
| 191 | return controller.pause(); |
|---|
| 192 | } |
|---|
| 193 | |
|---|
| 194 | |
|---|
| 195 | /** |
|---|
| 196 | * @inheritDoc |
|---|
| 197 | */ |
|---|
| 198 | public function stop():Boolean { |
|---|
| 199 | return controller.stop(); |
|---|
| 200 | } |
|---|
| 201 | |
|---|
| 202 | |
|---|
| 203 | /** |
|---|
| 204 | * @inheritDoc |
|---|
| 205 | */ |
|---|
| 206 | public function seek(position:Number):Boolean { |
|---|
| 207 | return controller.seek(position); |
|---|
| 208 | } |
|---|
| 209 | |
|---|
| 210 | |
|---|
| 211 | /** |
|---|
| 212 | * @inheritDoc |
|---|
| 213 | */ |
|---|
| 214 | public function load(item:*):Boolean { |
|---|
| 215 | return controller.load(item); |
|---|
| 216 | } |
|---|
| 217 | |
|---|
| 218 | |
|---|
| 219 | /** |
|---|
| 220 | * @inheritDoc |
|---|
| 221 | */ |
|---|
| 222 | public function playlistItem(index:Number):Boolean { |
|---|
| 223 | return controller.setPlaylistIndex(index); |
|---|
| 224 | } |
|---|
| 225 | |
|---|
| 226 | |
|---|
| 227 | /** |
|---|
| 228 | * @inheritDoc |
|---|
| 229 | */ |
|---|
| 230 | public function playlistNext():Boolean { |
|---|
| 231 | return controller.next(); |
|---|
| 232 | } |
|---|
| 233 | |
|---|
| 234 | |
|---|
| 235 | /** |
|---|
| 236 | * @inheritDoc |
|---|
| 237 | */ |
|---|
| 238 | public function playlistPrev():Boolean { |
|---|
| 239 | return controller.previous(); |
|---|
| 240 | } |
|---|
| 241 | |
|---|
| 242 | |
|---|
| 243 | /** |
|---|
| 244 | * @inheritDoc |
|---|
| 245 | */ |
|---|
| 246 | public function redraw():Boolean { |
|---|
| 247 | return controller.redraw(); |
|---|
| 248 | } |
|---|
| 249 | |
|---|
| 250 | |
|---|
| 251 | /** |
|---|
| 252 | * @inheritDoc |
|---|
| 253 | */ |
|---|
| 254 | public function get fullscreen():Boolean { |
|---|
| 255 | return model.fullscreen; |
|---|
| 256 | } |
|---|
| 257 | |
|---|
| 258 | |
|---|
| 259 | /** |
|---|
| 260 | * @inheritDoc |
|---|
| 261 | */ |
|---|
| 262 | public function set fullscreen(on:Boolean):void { |
|---|
| 263 | controller.fullscreen(on); |
|---|
| 264 | } |
|---|
| 265 | |
|---|
| 266 | |
|---|
| 267 | /** |
|---|
| 268 | * @inheritDoc |
|---|
| 269 | */ |
|---|
| 270 | public function link(index:Number = NaN):Boolean { |
|---|
| 271 | return controller.link(index); |
|---|
| 272 | } |
|---|
| 273 | |
|---|
| 274 | |
|---|
| 275 | /** |
|---|
| 276 | * @inheritDoc |
|---|
| 277 | */ |
|---|
| 278 | public function get controls():IPlayerComponents { |
|---|
| 279 | return view.components; |
|---|
| 280 | } |
|---|
| 281 | |
|---|
| 282 | |
|---|
| 283 | /** |
|---|
| 284 | * @inheritDoc |
|---|
| 285 | */ |
|---|
| 286 | public function overrideComponent(plugin:IPlayerComponent):void { |
|---|
| 287 | view.overrideComponent(plugin); |
|---|
| 288 | } |
|---|
| 289 | |
|---|
| 290 | /** |
|---|
| 291 | * @private |
|---|
| 292 | * |
|---|
| 293 | * This method is deprecated, and is used for backwards compatibility only. |
|---|
| 294 | */ |
|---|
| 295 | public function getPlugin(id:String):Object { |
|---|
| 296 | return view.getPlugin(id); |
|---|
| 297 | } |
|---|
| 298 | } |
|---|
| 299 | } |
|---|