| 1 | package com.longtailvideo.jwplayer.view { |
|---|
| 2 | import com.longtailvideo.jwplayer.events.GlobalEventDispatcher; |
|---|
| 3 | import com.longtailvideo.jwplayer.events.MediaEvent; |
|---|
| 4 | import com.longtailvideo.jwplayer.events.PlayerEvent; |
|---|
| 5 | import com.longtailvideo.jwplayer.events.PlayerStateEvent; |
|---|
| 6 | import com.longtailvideo.jwplayer.events.PlaylistEvent; |
|---|
| 7 | import com.longtailvideo.jwplayer.events.ViewEvent; |
|---|
| 8 | import com.longtailvideo.jwplayer.model.Model; |
|---|
| 9 | import com.longtailvideo.jwplayer.player.IPlayer; |
|---|
| 10 | import com.longtailvideo.jwplayer.player.PlayerState; |
|---|
| 11 | import com.longtailvideo.jwplayer.player.PlayerV4Emulation; |
|---|
| 12 | import com.longtailvideo.jwplayer.plugins.IPlugin; |
|---|
| 13 | import com.longtailvideo.jwplayer.plugins.PluginConfig; |
|---|
| 14 | import com.longtailvideo.jwplayer.utils.Animations; |
|---|
| 15 | import com.longtailvideo.jwplayer.utils.RootReference; |
|---|
| 16 | import com.longtailvideo.jwplayer.utils.Stretcher; |
|---|
| 17 | import com.longtailvideo.jwplayer.view.interfaces.IControlbarComponent; |
|---|
| 18 | import com.longtailvideo.jwplayer.view.interfaces.IDisplayComponent; |
|---|
| 19 | import com.longtailvideo.jwplayer.view.interfaces.IDockComponent; |
|---|
| 20 | import com.longtailvideo.jwplayer.view.interfaces.IPlayerComponent; |
|---|
| 21 | import com.longtailvideo.jwplayer.view.interfaces.IPlaylistComponent; |
|---|
| 22 | import com.longtailvideo.jwplayer.view.interfaces.ISkin; |
|---|
| 23 | |
|---|
| 24 | import flash.display.DisplayObject; |
|---|
| 25 | import flash.display.Loader; |
|---|
| 26 | import flash.display.MovieClip; |
|---|
| 27 | import flash.display.Sprite; |
|---|
| 28 | import flash.display.Stage; |
|---|
| 29 | import flash.display.StageAlign; |
|---|
| 30 | import flash.display.StageDisplayState; |
|---|
| 31 | import flash.display.StageScaleMode; |
|---|
| 32 | import flash.events.ErrorEvent; |
|---|
| 33 | import flash.events.Event; |
|---|
| 34 | import flash.events.IOErrorEvent; |
|---|
| 35 | import flash.net.URLRequest; |
|---|
| 36 | |
|---|
| 37 | public class View extends GlobalEventDispatcher { |
|---|
| 38 | private var _player:IPlayer; |
|---|
| 39 | private var _model:Model; |
|---|
| 40 | private var _skin:ISkin; |
|---|
| 41 | private var _components:IPlayerComponents; |
|---|
| 42 | private var _fullscreen:Boolean = false; |
|---|
| 43 | private var stage:Stage; |
|---|
| 44 | |
|---|
| 45 | private var _root:MovieClip; |
|---|
| 46 | |
|---|
| 47 | private var _backgroundLayer:MovieClip; |
|---|
| 48 | private var _mediaLayer:MovieClip; |
|---|
| 49 | private var _imageLayer:MovieClip; |
|---|
| 50 | private var _componentsLayer:MovieClip; |
|---|
| 51 | private var _logoLayer:MovieClip; |
|---|
| 52 | private var _pluginsLayer:MovieClip; |
|---|
| 53 | private var _plugins:Object; |
|---|
| 54 | |
|---|
| 55 | private var _lockLayer:MovieClip; |
|---|
| 56 | private var _lockPlugin:IPlugin; |
|---|
| 57 | private var _lockAnimator:Animations; |
|---|
| 58 | |
|---|
| 59 | private var _displayMasker:MovieClip; |
|---|
| 60 | |
|---|
| 61 | private var _image:Loader; |
|---|
| 62 | private var _logo:Logo; |
|---|
| 63 | |
|---|
| 64 | private var layoutManager:PlayerLayoutManager; |
|---|
| 65 | |
|---|
| 66 | [Embed(source="../../../../../assets/flash/loader/loader.swf")] |
|---|
| 67 | private var LoadingScreen:Class; |
|---|
| 68 | |
|---|
| 69 | [Embed(source="../../../../../assets/flash/loader/error.swf")] |
|---|
| 70 | private var ErrorScreen:Class; |
|---|
| 71 | |
|---|
| 72 | private var loaderScreen:Sprite; |
|---|
| 73 | private var loaderAnim:DisplayObject; |
|---|
| 74 | |
|---|
| 75 | public function View(player:IPlayer, model:Model) { |
|---|
| 76 | _player = player; |
|---|
| 77 | _model = model; |
|---|
| 78 | |
|---|
| 79 | RootReference.stage.scaleMode = StageScaleMode.NO_SCALE; |
|---|
| 80 | RootReference.stage.stage.align = StageAlign.TOP_LEFT; |
|---|
| 81 | |
|---|
| 82 | loaderScreen = new Sprite(); |
|---|
| 83 | loaderScreen.name = 'loaderScreen'; |
|---|
| 84 | |
|---|
| 85 | loaderAnim = new LoadingScreen() as DisplayObject; |
|---|
| 86 | loaderScreen.addChild(loaderAnim); |
|---|
| 87 | |
|---|
| 88 | RootReference.stage.addChildAt(loaderScreen, 0); |
|---|
| 89 | |
|---|
| 90 | if (RootReference.stage.stageWidth > 0) { |
|---|
| 91 | resizeStage(); |
|---|
| 92 | } else { |
|---|
| 93 | RootReference.stage.addEventListener(Event.RESIZE, resizeStage); |
|---|
| 94 | RootReference.stage.addEventListener(Event.ADDED_TO_STAGE, resizeStage); |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | _root = new MovieClip(); |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | private function resizeStage(evt:Event=null):void { |
|---|
| 101 | RootReference.stage.removeEventListener(Event.RESIZE, resizeStage); |
|---|
| 102 | RootReference.stage.removeEventListener(Event.ADDED_TO_STAGE, resizeStage); |
|---|
| 103 | |
|---|
| 104 | loaderScreen.graphics.clear(); |
|---|
| 105 | loaderScreen.graphics.beginFill(0, 1); |
|---|
| 106 | loaderScreen.graphics.drawRect(0, 0, RootReference.stage.stageWidth, RootReference.stage.stageHeight); |
|---|
| 107 | loaderScreen.graphics.endFill(); |
|---|
| 108 | |
|---|
| 109 | loaderAnim.x = (RootReference.stage.stageWidth - loaderAnim.width) / 2; |
|---|
| 110 | loaderAnim.y = (RootReference.stage.stageHeight - loaderAnim.height) / 2; |
|---|
| 111 | } |
|---|
| 112 | |
|---|
| 113 | public function get skin():ISkin { |
|---|
| 114 | return _skin; |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | |
|---|
| 118 | public function set skin(skn:ISkin):void { |
|---|
| 119 | _skin = skn; |
|---|
| 120 | } |
|---|
| 121 | |
|---|
| 122 | public function setupView():void { |
|---|
| 123 | setupLayers(); |
|---|
| 124 | setupComponents(); |
|---|
| 125 | |
|---|
| 126 | RootReference.stage.addEventListener(Event.FULLSCREEN, resizeHandler); |
|---|
| 127 | RootReference.stage.addEventListener(Event.RESIZE, resizeHandler); |
|---|
| 128 | |
|---|
| 129 | _model.addEventListener(MediaEvent.JWPLAYER_MEDIA_LOADED, mediaLoaded); |
|---|
| 130 | _model.playlist.addEventListener(PlaylistEvent.JWPLAYER_PLAYLIST_ITEM, itemHandler); |
|---|
| 131 | _model.addEventListener(PlayerStateEvent.JWPLAYER_PLAYER_STATE, stateHandler); |
|---|
| 132 | |
|---|
| 133 | layoutManager = new PlayerLayoutManager(_player); |
|---|
| 134 | var menu:RightclickMenu = new RightclickMenu(_model, _root); |
|---|
| 135 | menu.addGlobalListener(forward); |
|---|
| 136 | |
|---|
| 137 | redraw(); |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | public function completeView(isError:Boolean=false, errorMsg:String=""):void { |
|---|
| 141 | if (!isError) { |
|---|
| 142 | RootReference.stage.removeChild(loaderScreen); |
|---|
| 143 | RootReference.stage.addChildAt(_root, 0); |
|---|
| 144 | } else { |
|---|
| 145 | loaderScreen.removeChild(loaderAnim); |
|---|
| 146 | var errorScreen:DisplayObject = new ErrorScreen() as DisplayObject; |
|---|
| 147 | errorScreen.x = (loaderScreen.width - errorScreen.width) / 2; |
|---|
| 148 | errorScreen.y = (loaderScreen.height - errorScreen.height) / 2; |
|---|
| 149 | loaderScreen.addChild(errorScreen); |
|---|
| 150 | } |
|---|
| 151 | } |
|---|
| 152 | |
|---|
| 153 | private function setupLayers():void { |
|---|
| 154 | _backgroundLayer = setupLayer("background", 0); |
|---|
| 155 | setupBackground(); |
|---|
| 156 | |
|---|
| 157 | _mediaLayer = setupLayer("media", 1); |
|---|
| 158 | _mediaLayer.visible = false; |
|---|
| 159 | |
|---|
| 160 | _imageLayer = setupLayer("image", 2); |
|---|
| 161 | _image = new Loader(); |
|---|
| 162 | |
|---|
| 163 | _componentsLayer = setupLayer("components", 3); |
|---|
| 164 | |
|---|
| 165 | _pluginsLayer = setupLayer("plugins", 4); |
|---|
| 166 | _plugins = {}; |
|---|
| 167 | |
|---|
| 168 | _logoLayer = setupLayer("logo", 5); |
|---|
| 169 | _logo = new Logo(_player); |
|---|
| 170 | _logoLayer.addChild(_logo); |
|---|
| 171 | |
|---|
| 172 | _lockLayer = setupLayer("lock", 6); |
|---|
| 173 | setupLock(); |
|---|
| 174 | } |
|---|
| 175 | |
|---|
| 176 | private function setupLayer(name:String, index:Number):MovieClip { |
|---|
| 177 | var layer:MovieClip = new MovieClip(); |
|---|
| 178 | _root.addChildAt(layer, index); |
|---|
| 179 | layer.name = name; |
|---|
| 180 | layer.x = 0; |
|---|
| 181 | layer.y = 0; |
|---|
| 182 | return layer; |
|---|
| 183 | } |
|---|
| 184 | |
|---|
| 185 | private function setupBackground():void { |
|---|
| 186 | var background:MovieClip = new MovieClip(); |
|---|
| 187 | background.name = "background"; |
|---|
| 188 | _backgroundLayer.addChild(background); |
|---|
| 189 | background.graphics.beginFill(_player.config.screencolor ? _player.config.screencolor.color : 0x000000, 1); |
|---|
| 190 | background.graphics.drawRect(0, 0, 1, 1); |
|---|
| 191 | background.graphics.endFill(); |
|---|
| 192 | } |
|---|
| 193 | |
|---|
| 194 | private function setupDisplayMask():void { |
|---|
| 195 | _displayMasker = new MovieClip(); |
|---|
| 196 | _displayMasker.graphics.beginFill(0x000000, 1); |
|---|
| 197 | _displayMasker.graphics.drawRect(0, 0, _player.config.width, _player.config.height); |
|---|
| 198 | _displayMasker.graphics.endFill(); |
|---|
| 199 | |
|---|
| 200 | _backgroundLayer.mask = _displayMasker; |
|---|
| 201 | _imageLayer.mask = _displayMasker; |
|---|
| 202 | _mediaLayer.mask = _displayMasker; |
|---|
| 203 | } |
|---|
| 204 | |
|---|
| 205 | private function setupLock():void { |
|---|
| 206 | _lockLayer.mouseEnabled = false; |
|---|
| 207 | _lockLayer.mouseChildren = true; |
|---|
| 208 | _lockLayer.visible = false; |
|---|
| 209 | _lockLayer.alpha = 0; |
|---|
| 210 | _lockLayer.graphics.beginFill(0x000000, 0.7); |
|---|
| 211 | _lockLayer.graphics.drawRect(0, 0, 1, 1); |
|---|
| 212 | _lockLayer.graphics.endFill(); |
|---|
| 213 | _lockAnimator = new Animations(_lockLayer); |
|---|
| 214 | } |
|---|
| 215 | |
|---|
| 216 | private function setupComponents():void { |
|---|
| 217 | _components = new PlayerComponents(_player); |
|---|
| 218 | |
|---|
| 219 | setupComponent(_components.display, 0); |
|---|
| 220 | setupComponent(_components.playlist, 1); |
|---|
| 221 | setupComponent(_components.controlbar, 2); |
|---|
| 222 | setupComponent(_components.dock, 3); |
|---|
| 223 | } |
|---|
| 224 | |
|---|
| 225 | private function setupComponent(component:IPlayerComponent, index:Number):void { |
|---|
| 226 | component.addGlobalListener(forward); |
|---|
| 227 | _componentsLayer.addChildAt(component as DisplayObject, index); |
|---|
| 228 | } |
|---|
| 229 | |
|---|
| 230 | |
|---|
| 231 | private function resizeHandler(event:Event):void { |
|---|
| 232 | redraw(); |
|---|
| 233 | |
|---|
| 234 | var currentFSMode:Boolean = (RootReference.stage.displayState == StageDisplayState.FULL_SCREEN); |
|---|
| 235 | if (_model.fullscreen != currentFSMode) { |
|---|
| 236 | dispatchEvent(new ViewEvent(ViewEvent.JWPLAYER_VIEW_FULLSCREEN, currentFSMode)); |
|---|
| 237 | } |
|---|
| 238 | } |
|---|
| 239 | |
|---|
| 240 | |
|---|
| 241 | public function fullscreen(mode:Boolean=true):void { |
|---|
| 242 | RootReference.stage.displayState = mode ? StageDisplayState.FULL_SCREEN : StageDisplayState.NORMAL; |
|---|
| 243 | } |
|---|
| 244 | |
|---|
| 245 | /** Redraws the plugins and player components **/ |
|---|
| 246 | public function redraw():void { |
|---|
| 247 | layoutManager.resize(RootReference.stage.stageWidth, RootReference.stage.stageHeight); |
|---|
| 248 | |
|---|
| 249 | _components.resize(_player.config.width, _player.config.height); |
|---|
| 250 | |
|---|
| 251 | resizeBackground(); |
|---|
| 252 | resizeMasker(); |
|---|
| 253 | |
|---|
| 254 | if (_imageLayer.numChildren) { |
|---|
| 255 | _imageLayer.x = _components.display.x; |
|---|
| 256 | _imageLayer.y = _components.display.y; |
|---|
| 257 | Stretcher.stretch(_image, _player.config.width, _player.config.height, _player.config.stretching); |
|---|
| 258 | } |
|---|
| 259 | |
|---|
| 260 | if (_mediaLayer.numChildren && _model.media.display) { |
|---|
| 261 | _mediaLayer.x = _components.display.x; |
|---|
| 262 | _mediaLayer.y = _components.display.y; |
|---|
| 263 | _model.media.resize(_player.config.width, _player.config.height); |
|---|
| 264 | } |
|---|
| 265 | |
|---|
| 266 | if (_logoLayer.numChildren) { |
|---|
| 267 | _logoLayer.x = _components.display.x; |
|---|
| 268 | _logoLayer.y = _components.display.y; |
|---|
| 269 | _logo.resize(_player.config.width, _player.config.height); |
|---|
| 270 | } |
|---|
| 271 | |
|---|
| 272 | for (var i:Number = 0; i < _pluginsLayer.numChildren; i++) { |
|---|
| 273 | var plug:IPlugin = _pluginsLayer.getChildAt(i) as IPlugin; |
|---|
| 274 | var plugDisplay:DisplayObject = plug as DisplayObject; |
|---|
| 275 | if (plug && plugDisplay) { |
|---|
| 276 | var cfg:PluginConfig = _player.config.pluginConfig(plug.id); |
|---|
| 277 | if (cfg['visible']) { |
|---|
| 278 | plugDisplay.visible = true; |
|---|
| 279 | plugDisplay.x = cfg['x']; |
|---|
| 280 | plugDisplay.y = cfg['y']; |
|---|
| 281 | plug.resize(cfg.width, cfg.height); |
|---|
| 282 | } else { |
|---|
| 283 | plugDisplay.visible = false; |
|---|
| 284 | } |
|---|
| 285 | } |
|---|
| 286 | } |
|---|
| 287 | |
|---|
| 288 | resizeLock(); |
|---|
| 289 | |
|---|
| 290 | PlayerV4Emulation.getInstance(_player).resize(_player.config.width, _player.config.height); |
|---|
| 291 | } |
|---|
| 292 | |
|---|
| 293 | private function resizeBackground():void { |
|---|
| 294 | var bg:DisplayObject = _backgroundLayer.getChildByName("background"); |
|---|
| 295 | bg.width = _player.config.width; |
|---|
| 296 | bg.height = _player.config.height; |
|---|
| 297 | bg.x = _components.display.x; |
|---|
| 298 | bg.y = _components.display.y; |
|---|
| 299 | } |
|---|
| 300 | |
|---|
| 301 | private function resizeLock():void { |
|---|
| 302 | _lockLayer.width = RootReference.stage.stageWidth; |
|---|
| 303 | _lockLayer.height = RootReference.stage.stageHeight; |
|---|
| 304 | _lockLayer.x = _lockLayer.y = 0; |
|---|
| 305 | |
|---|
| 306 | if (_lockPlugin) { |
|---|
| 307 | (_lockPlugin as DisplayObject).x = 0; |
|---|
| 308 | (_lockPlugin as DisplayObject).y = 0; |
|---|
| 309 | var cfg:PluginConfig = _player.config.pluginConfig(_lockPlugin.id); |
|---|
| 310 | cfg['x'] = cfg['y'] = 0; |
|---|
| 311 | cfg['width'] = _lockLayer.width; |
|---|
| 312 | cfg['height'] = _lockLayer.height; |
|---|
| 313 | _lockPlugin.resize(cfg['width'], cfg['height']); |
|---|
| 314 | } |
|---|
| 315 | } |
|---|
| 316 | |
|---|
| 317 | private function resizeMasker():void { |
|---|
| 318 | if (_displayMasker == null) setupDisplayMask(); |
|---|
| 319 | |
|---|
| 320 | _displayMasker.graphics.clear(); |
|---|
| 321 | _displayMasker.graphics.beginFill(0, 1); |
|---|
| 322 | _displayMasker.graphics.drawRect(_components.display.x, _components.display.y, _player.config.width, _player.config.height); |
|---|
| 323 | _displayMasker.graphics.endFill(); |
|---|
| 324 | } |
|---|
| 325 | |
|---|
| 326 | public function get components():IPlayerComponents { |
|---|
| 327 | return _components; |
|---|
| 328 | } |
|---|
| 329 | |
|---|
| 330 | public function overrideComponent(newComponent:IPlayerComponent):void { |
|---|
| 331 | if (newComponent is IControlbarComponent) { |
|---|
| 332 | // Replace controlbar |
|---|
| 333 | } else if (newComponent is IDisplayComponent) { |
|---|
| 334 | // Replace display |
|---|
| 335 | } else if (newComponent is IDockComponent) { |
|---|
| 336 | // Replace dock |
|---|
| 337 | } else if (newComponent is IPlaylistComponent) { |
|---|
| 338 | // Replace playlist |
|---|
| 339 | } else { |
|---|
| 340 | dispatchEvent(new ErrorEvent(ErrorEvent.ERROR, false, false, "Component must implement a component interface")); |
|---|
| 341 | } |
|---|
| 342 | } |
|---|
| 343 | |
|---|
| 344 | public function addPlugin(id:String, plugin:IPlugin):void { |
|---|
| 345 | try { |
|---|
| 346 | var plugDO:DisplayObject = plugin as DisplayObject; |
|---|
| 347 | if (!_plugins[id] && plugDO != null) { |
|---|
| 348 | _plugins[id] = plugDO; |
|---|
| 349 | _pluginsLayer.addChild(plugDO); |
|---|
| 350 | //_pluginsLayer[id] = plugDO; |
|---|
| 351 | } |
|---|
| 352 | } catch (e:Error) { |
|---|
| 353 | dispatchEvent(new ErrorEvent(ErrorEvent.ERROR, false, false, e.message)); |
|---|
| 354 | } |
|---|
| 355 | } |
|---|
| 356 | |
|---|
| 357 | public function removePlugin(plugin:IPlugin):void { |
|---|
| 358 | var id:String = plugin.id; |
|---|
| 359 | if (id && _plugins[id] is IPlugin) { |
|---|
| 360 | _pluginsLayer.removeChild(_plugins[id]); |
|---|
| 361 | delete _plugins[id]; |
|---|
| 362 | } |
|---|
| 363 | } |
|---|
| 364 | |
|---|
| 365 | |
|---|
| 366 | public function loadedPlugins():Array { |
|---|
| 367 | var list:Array = []; |
|---|
| 368 | for (var pluginId:String in _plugins) { |
|---|
| 369 | if (_plugins[pluginId] is IPlugin) { |
|---|
| 370 | list.push(pluginId); |
|---|
| 371 | } |
|---|
| 372 | } |
|---|
| 373 | return list; |
|---|
| 374 | } |
|---|
| 375 | |
|---|
| 376 | public function getPlugin(id:String):IPlugin { |
|---|
| 377 | return _plugins[id] as IPlugin; |
|---|
| 378 | } |
|---|
| 379 | |
|---|
| 380 | public function bringPluginToFront(id:String):void { |
|---|
| 381 | var plugin:IPlugin = getPlugin(id); |
|---|
| 382 | _pluginsLayer.setChildIndex(plugin as DisplayObject, _pluginsLayer.numChildren - 1); |
|---|
| 383 | } |
|---|
| 384 | |
|---|
| 385 | private function mediaLoaded(evt:MediaEvent):void { |
|---|
| 386 | _mediaLayer.x = _components.display.x; |
|---|
| 387 | _mediaLayer.y = _components.display.y; |
|---|
| 388 | if (_model.media.display) { |
|---|
| 389 | _model.media.resize(_player.config.width, _player.config.height); |
|---|
| 390 | _mediaLayer.addChild(_model.media.display); |
|---|
| 391 | } |
|---|
| 392 | } |
|---|
| 393 | |
|---|
| 394 | private function itemHandler(evt:PlaylistEvent):void { |
|---|
| 395 | while (_mediaLayer.numChildren) { |
|---|
| 396 | _mediaLayer.removeChildAt(0); |
|---|
| 397 | } |
|---|
| 398 | if (_model.playlist.currentItem && _model.playlist.currentItem.image) { |
|---|
| 399 | loadImage(_model.playlist.currentItem.image); |
|---|
| 400 | |
|---|
| 401 | } |
|---|
| 402 | } |
|---|
| 403 | |
|---|
| 404 | private function loadImage(url:String):void { |
|---|
| 405 | while (_imageLayer.numChildren) { |
|---|
| 406 | _imageLayer.removeChildAt(0); |
|---|
| 407 | } |
|---|
| 408 | |
|---|
| 409 | _image = new Loader(); |
|---|
| 410 | _image.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, imageError); |
|---|
| 411 | _image.contentLoaderInfo.addEventListener(Event.COMPLETE, imageComplete); |
|---|
| 412 | _image.load(new URLRequest(url)); |
|---|
| 413 | } |
|---|
| 414 | |
|---|
| 415 | private function imageComplete(evt:Event):void { |
|---|
| 416 | _imageLayer.addChild(_image); |
|---|
| 417 | _imageLayer.x = _components.display.x; |
|---|
| 418 | _imageLayer.y = _components.display.y; |
|---|
| 419 | Stretcher.stretch(_image, _player.config.width, _player.config.height, _player.config.stretching); |
|---|
| 420 | } |
|---|
| 421 | |
|---|
| 422 | private function imageError(evt:IOErrorEvent):void { |
|---|
| 423 | _image = null; |
|---|
| 424 | dispatchEvent(new PlayerEvent(PlayerEvent.JWPLAYER_ERROR, evt.text)); |
|---|
| 425 | } |
|---|
| 426 | |
|---|
| 427 | private function stateHandler(evt:PlayerStateEvent):void { |
|---|
| 428 | switch (evt.newstate) { |
|---|
| 429 | case PlayerState.IDLE: |
|---|
| 430 | _imageLayer.visible = true; |
|---|
| 431 | _mediaLayer.visible = false; |
|---|
| 432 | _logoLayer.visible = false; |
|---|
| 433 | break; |
|---|
| 434 | case PlayerState.PLAYING: |
|---|
| 435 | if (_model.media.display) { |
|---|
| 436 | _imageLayer.visible = false; |
|---|
| 437 | _mediaLayer.visible = true; |
|---|
| 438 | } |
|---|
| 439 | _logoLayer.visible = true; |
|---|
| 440 | break; |
|---|
| 441 | } |
|---|
| 442 | } |
|---|
| 443 | |
|---|
| 444 | private function forward(evt:Event):void { |
|---|
| 445 | if (evt is PlayerEvent) dispatchEvent(evt); |
|---|
| 446 | } |
|---|
| 447 | |
|---|
| 448 | public function lock(plugin:IPlugin):void { |
|---|
| 449 | _lockAnimator.fade(1); |
|---|
| 450 | |
|---|
| 451 | var idx:Number = _pluginsLayer.getChildIndex(plugin as DisplayObject); |
|---|
| 452 | if (idx >= 0) { |
|---|
| 453 | _lockPlugin = _pluginsLayer.getChildAt(idx) as IPlugin; |
|---|
| 454 | _pluginsLayer.removeChild(_lockPlugin as DisplayObject); |
|---|
| 455 | _lockLayer.addChild(_lockPlugin as DisplayObject); |
|---|
| 456 | } |
|---|
| 457 | |
|---|
| 458 | redraw(); |
|---|
| 459 | } |
|---|
| 460 | |
|---|
| 461 | public function unlock(plugin:IPlugin):void { |
|---|
| 462 | if (plugin == _lockPlugin) { |
|---|
| 463 | _lockLayer.removeChild(_lockPlugin as DisplayObject); |
|---|
| 464 | _pluginsLayer.addChild(_lockPlugin as DisplayObject); |
|---|
| 465 | _lockPlugin = null; |
|---|
| 466 | } |
|---|
| 467 | _lockAnimator.fade(0); |
|---|
| 468 | |
|---|
| 469 | redraw(); |
|---|
| 470 | } |
|---|
| 471 | |
|---|
| 472 | } |
|---|
| 473 | } |
|---|