| 1 | package com.longtailvideo.jwplayer.player { |
|---|
| 2 | import com.jeroenwijering.events.AbstractView; |
|---|
| 3 | import com.jeroenwijering.events.ControllerEvent; |
|---|
| 4 | import com.jeroenwijering.events.ModelEvent; |
|---|
| 5 | import com.jeroenwijering.events.ModelStates; |
|---|
| 6 | import com.longtailvideo.jwplayer.controller.Controller; |
|---|
| 7 | import com.longtailvideo.jwplayer.events.MediaEvent; |
|---|
| 8 | import com.longtailvideo.jwplayer.events.PlayerEvent; |
|---|
| 9 | import com.longtailvideo.jwplayer.events.PlayerStateEvent; |
|---|
| 10 | import com.longtailvideo.jwplayer.events.PlaylistEvent; |
|---|
| 11 | import com.longtailvideo.jwplayer.events.ViewEvent; |
|---|
| 12 | import com.longtailvideo.jwplayer.model.IPlaylist; |
|---|
| 13 | import com.longtailvideo.jwplayer.model.Model; |
|---|
| 14 | import com.longtailvideo.jwplayer.model.PlaylistItem; |
|---|
| 15 | import com.longtailvideo.jwplayer.model.PlaylistItemLevel; |
|---|
| 16 | import com.longtailvideo.jwplayer.plugins.IPlugin; |
|---|
| 17 | import com.longtailvideo.jwplayer.plugins.PluginConfig; |
|---|
| 18 | import com.longtailvideo.jwplayer.plugins.V4Plugin; |
|---|
| 19 | import com.longtailvideo.jwplayer.utils.Logger; |
|---|
| 20 | import com.longtailvideo.jwplayer.utils.Strings; |
|---|
| 21 | import com.longtailvideo.jwplayer.view.interfaces.IControlbarComponent; |
|---|
| 22 | import com.longtailvideo.jwplayer.view.interfaces.IDisplayComponent; |
|---|
| 23 | import com.longtailvideo.jwplayer.view.interfaces.IDockComponent; |
|---|
| 24 | import com.longtailvideo.jwplayer.view.interfaces.IPlaylistComponent; |
|---|
| 25 | |
|---|
| 26 | import flash.display.DisplayObject; |
|---|
| 27 | import flash.events.EventDispatcher; |
|---|
| 28 | import flash.utils.describeType; |
|---|
| 29 | |
|---|
| 30 | /** |
|---|
| 31 | * This singleton class acts as a wrapper between the Player and plugins or javascripts that were |
|---|
| 32 | * written for version 4 of the player. It extends version 4's AbstractView class, and translates |
|---|
| 33 | * Player 5 event dispatches into their version 4 counterparts. |
|---|
| 34 | * |
|---|
| 35 | * @see com.longtailvideo.jwplayer.plugins.V4Plugin |
|---|
| 36 | */ |
|---|
| 37 | public class PlayerV4Emulation extends AbstractView { |
|---|
| 38 | private static var instance:PlayerV4Emulation; |
|---|
| 39 | |
|---|
| 40 | private var _player:IPlayer; |
|---|
| 41 | |
|---|
| 42 | private var viewEventDispatcher:EventDispatcher; |
|---|
| 43 | private var modelEventDispatcher:EventDispatcher; |
|---|
| 44 | private var controllerEventDispatcher:EventDispatcher; |
|---|
| 45 | |
|---|
| 46 | private var id:String; |
|---|
| 47 | private var client:String; |
|---|
| 48 | private var version:String; |
|---|
| 49 | |
|---|
| 50 | public function PlayerV4Emulation(player:IPlayer) { |
|---|
| 51 | viewEventDispatcher = new EventDispatcher(); |
|---|
| 52 | modelEventDispatcher = new EventDispatcher(); |
|---|
| 53 | controllerEventDispatcher = new EventDispatcher(); |
|---|
| 54 | |
|---|
| 55 | _player = player; |
|---|
| 56 | _player.addEventListener(PlayerEvent.JWPLAYER_READY, playerReady); |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | public static function getInstance(player:IPlayer):PlayerV4Emulation { |
|---|
| 60 | if (!instance) { |
|---|
| 61 | instance = new PlayerV4Emulation(player); |
|---|
| 62 | } |
|---|
| 63 | return instance; |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | private function playerReady(evt:PlayerEvent):void { |
|---|
| 67 | id = evt.id; |
|---|
| 68 | client = evt.client; |
|---|
| 69 | version = evt.version; |
|---|
| 70 | |
|---|
| 71 | dispatchEvent(new com.jeroenwijering.events.PlayerEvent(com.jeroenwijering.events.PlayerEvent.READY)); |
|---|
| 72 | setupListeners(); |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | private function setupListeners():void { |
|---|
| 76 | |
|---|
| 77 | var m:Model; |
|---|
| 78 | var v:IControlbarComponent; |
|---|
| 79 | var c:Controller |
|---|
| 80 | |
|---|
| 81 | _player.addEventListener(PlayerEvent.JWPLAYER_ERROR, errorHandler); |
|---|
| 82 | |
|---|
| 83 | _player.addEventListener(MediaEvent.JWPLAYER_MEDIA_BUFFER, mediaBuffer); |
|---|
| 84 | _player.addEventListener(MediaEvent.JWPLAYER_MEDIA_ERROR, mediaError); |
|---|
| 85 | _player.addEventListener(MediaEvent.JWPLAYER_MEDIA_LOADED, mediaLoaded); |
|---|
| 86 | _player.addEventListener(MediaEvent.JWPLAYER_MEDIA_TIME, mediaTime); |
|---|
| 87 | _player.addEventListener(MediaEvent.JWPLAYER_MEDIA_VOLUME, mediaVolume); |
|---|
| 88 | _player.addEventListener(MediaEvent.JWPLAYER_MEDIA_MUTE, mediaMute); |
|---|
| 89 | _player.addEventListener(MediaEvent.JWPLAYER_MEDIA_META, mediaMeta); |
|---|
| 90 | _player.addEventListener(MediaEvent.JWPLAYER_MEDIA_COMPLETE, mediaComplete); |
|---|
| 91 | _player.addEventListener(PlayerStateEvent.JWPLAYER_PLAYER_STATE, stateHandler); |
|---|
| 92 | |
|---|
| 93 | _player.addEventListener(ViewEvent.JWPLAYER_VIEW_FULLSCREEN, viewFullscreen); |
|---|
| 94 | _player.addEventListener(ViewEvent.JWPLAYER_VIEW_ITEM, viewItem); |
|---|
| 95 | _player.addEventListener(ViewEvent.JWPLAYER_VIEW_LOAD, viewLoad); |
|---|
| 96 | _player.addEventListener(ViewEvent.JWPLAYER_VIEW_MUTE, viewMute); |
|---|
| 97 | _player.addEventListener(ViewEvent.JWPLAYER_VIEW_NEXT, viewNext); |
|---|
| 98 | _player.addEventListener(ViewEvent.JWPLAYER_VIEW_PAUSE, viewPause); |
|---|
| 99 | _player.addEventListener(ViewEvent.JWPLAYER_VIEW_PLAY, viewPlay); |
|---|
| 100 | _player.addEventListener(ViewEvent.JWPLAYER_VIEW_PREV, viewPrev); |
|---|
| 101 | _player.addEventListener(ViewEvent.JWPLAYER_VIEW_SEEK, viewSeek); |
|---|
| 102 | _player.addEventListener(ViewEvent.JWPLAYER_VIEW_STOP, viewStop); |
|---|
| 103 | _player.addEventListener(ViewEvent.JWPLAYER_VIEW_VOLUME, viewVolume); |
|---|
| 104 | |
|---|
| 105 | _player.addEventListener(PlaylistEvent.JWPLAYER_PLAYLIST_ITEM, playlistItem); |
|---|
| 106 | _player.addEventListener(PlaylistEvent.JWPLAYER_PLAYLIST_LOADED, playlistLoad); |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | // Player Event Handlers |
|---|
| 110 | |
|---|
| 111 | private function errorHandler(evt:PlayerEvent):void { |
|---|
| 112 | controllerEventDispatcher.dispatchEvent(new ControllerEvent(ControllerEvent.ERROR, {message:evt.message, id:id, client:client, version:version})); |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | // Media Event Handlers |
|---|
| 116 | |
|---|
| 117 | private function mediaBuffer(evt:MediaEvent):void { |
|---|
| 118 | modelEventDispatcher.dispatchEvent(new ModelEvent(ModelEvent.BUFFER, {percentage:evt.bufferPercent, id:id, client:client, version:version})); |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | private function mediaError(evt:MediaEvent):void { |
|---|
| 122 | modelEventDispatcher.dispatchEvent(new ModelEvent(ModelEvent.ERROR, {message:evt.message, id:id, client:client, version:version})); |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | private function mediaLoaded(evt:MediaEvent):void { |
|---|
| 126 | modelEventDispatcher.dispatchEvent(new ModelEvent(ModelEvent.LOADED, {loaded:0, total:0, offset:0, id:id, client:client, version:version})); |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | private function mediaTime(evt:MediaEvent):void { |
|---|
| 130 | modelEventDispatcher.dispatchEvent(new ModelEvent(ModelEvent.TIME, {duration:evt.duration, position:evt.position, id:id, client:client, version:version})); |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | private function mediaVolume(evt:MediaEvent):void { |
|---|
| 134 | controllerEventDispatcher.dispatchEvent(new ControllerEvent(ControllerEvent.VOLUME, {percentage:evt.volume, id:id, client:client, version:version})); |
|---|
| 135 | } |
|---|
| 136 | |
|---|
| 137 | private function mediaMute(evt:MediaEvent):void { |
|---|
| 138 | controllerEventDispatcher.dispatchEvent(new ControllerEvent(ControllerEvent.MUTE, {state:evt.mute, id:id, client:client, version:version})); |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | |
|---|
| 142 | private function mediaMeta(evt:MediaEvent):void { |
|---|
| 143 | evt.metadata['id'] = id; |
|---|
| 144 | evt.metadata['client'] = client; |
|---|
| 145 | evt.metadata['version'] = version; |
|---|
| 146 | modelEventDispatcher.dispatchEvent(new ModelEvent(ModelEvent.META, evt.metadata)); |
|---|
| 147 | } |
|---|
| 148 | |
|---|
| 149 | private function mediaComplete(evt:MediaEvent):void { |
|---|
| 150 | modelEventDispatcher.dispatchEvent(new ModelEvent(ModelEvent.STATE, {id:id, oldstate:_player.state, newstate:ModelStates.COMPLETED})); |
|---|
| 151 | } |
|---|
| 152 | |
|---|
| 153 | private function stateHandler(evt:PlayerStateEvent):void { |
|---|
| 154 | if (evt.newstate == PlayerState.IDLE && (evt.oldstate == PlayerState.BUFFERING || evt.oldstate == PlayerState.PLAYING)) { |
|---|
| 155 | controllerEventDispatcher.dispatchEvent(new ControllerEvent(ControllerEvent.STOP, {id:id, client:client, version:version})); |
|---|
| 156 | } |
|---|
| 157 | |
|---|
| 158 | modelEventDispatcher.dispatchEvent(new ModelEvent(ModelEvent.STATE, {id:id, oldstate:evt.oldstate, newstate:evt.newstate})); |
|---|
| 159 | } |
|---|
| 160 | |
|---|
| 161 | // View Event Handlers |
|---|
| 162 | |
|---|
| 163 | private function viewFullscreen(evt:ViewEvent):void { |
|---|
| 164 | viewEventDispatcher.dispatchEvent(new com.jeroenwijering.events.ViewEvent(com.jeroenwijering.events.ViewEvent.FULLSCREEN, {state:evt.data, id:id, client:client, version:version})); |
|---|
| 165 | } |
|---|
| 166 | |
|---|
| 167 | private function viewItem(evt:ViewEvent):void { |
|---|
| 168 | viewEventDispatcher.dispatchEvent(new com.jeroenwijering.events.ViewEvent(com.jeroenwijering.events.ViewEvent.ITEM, {index:evt.data, id:id, client:client, version:version})); |
|---|
| 169 | } |
|---|
| 170 | |
|---|
| 171 | private function viewLoad(evt:ViewEvent):void { |
|---|
| 172 | viewEventDispatcher.dispatchEvent(new com.jeroenwijering.events.ViewEvent(com.jeroenwijering.events.ViewEvent.LOAD, {object:evt.data, id:id, client:client, version:version})); |
|---|
| 173 | } |
|---|
| 174 | |
|---|
| 175 | private function viewMute(evt:ViewEvent):void { |
|---|
| 176 | viewEventDispatcher.dispatchEvent(new com.jeroenwijering.events.ViewEvent(com.jeroenwijering.events.ViewEvent.MUTE, {state:evt.data, id:id, client:client, version:version})); |
|---|
| 177 | controllerEventDispatcher.dispatchEvent(new ControllerEvent(ControllerEvent.MUTE, {state:evt.data, id:id, client:client, version:version})); |
|---|
| 178 | } |
|---|
| 179 | |
|---|
| 180 | private function viewNext(evt:ViewEvent):void { |
|---|
| 181 | viewEventDispatcher.dispatchEvent(new com.jeroenwijering.events.ViewEvent(com.jeroenwijering.events.ViewEvent.NEXT, {id:id, client:client, version:version})); |
|---|
| 182 | } |
|---|
| 183 | |
|---|
| 184 | private function viewPause(evt:ViewEvent):void { |
|---|
| 185 | viewEventDispatcher.dispatchEvent(new com.jeroenwijering.events.ViewEvent(com.jeroenwijering.events.ViewEvent.PLAY, {state:false, id:id, client:client, version:version})); |
|---|
| 186 | controllerEventDispatcher.dispatchEvent(new ControllerEvent(ControllerEvent.PLAY, {state:false, id:id, client:client, version:version})); |
|---|
| 187 | } |
|---|
| 188 | |
|---|
| 189 | private function viewPlay(evt:ViewEvent):void { |
|---|
| 190 | viewEventDispatcher.dispatchEvent(new com.jeroenwijering.events.ViewEvent(com.jeroenwijering.events.ViewEvent.PLAY, {state:true, id:id, client:client, version:version})); |
|---|
| 191 | controllerEventDispatcher.dispatchEvent(new ControllerEvent(ControllerEvent.PLAY, {state:true, id:id, client:client, version:version})); |
|---|
| 192 | } |
|---|
| 193 | |
|---|
| 194 | private function viewPrev(evt:ViewEvent):void { |
|---|
| 195 | viewEventDispatcher.dispatchEvent(new com.jeroenwijering.events.ViewEvent(com.jeroenwijering.events.ViewEvent.PREV, {id:id, client:client, version:version})); |
|---|
| 196 | } |
|---|
| 197 | |
|---|
| 198 | private function viewRedraw(width:Number, height:Number):void { |
|---|
| 199 | viewEventDispatcher.dispatchEvent(new com.jeroenwijering.events.ViewEvent(com.jeroenwijering.events.ViewEvent.REDRAW, {id:id, client:client, version:version})); |
|---|
| 200 | controllerEventDispatcher.dispatchEvent(new ControllerEvent(ControllerEvent.RESIZE, {width:width, height:height, fullscreen:_player.fullscreen, client:client, version:version})); |
|---|
| 201 | } |
|---|
| 202 | |
|---|
| 203 | private function viewSeek(evt:ViewEvent):void { |
|---|
| 204 | viewEventDispatcher.dispatchEvent(new com.jeroenwijering.events.ViewEvent(com.jeroenwijering.events.ViewEvent.SEEK, {position:evt.data, id:id, client:client, version:version})); |
|---|
| 205 | controllerEventDispatcher.dispatchEvent(new ControllerEvent(ControllerEvent.SEEK, {position:evt.data, id:id, client:client, version:version})); |
|---|
| 206 | } |
|---|
| 207 | |
|---|
| 208 | private function viewStop(evt:ViewEvent):void { |
|---|
| 209 | viewEventDispatcher.dispatchEvent(new com.jeroenwijering.events.ViewEvent(com.jeroenwijering.events.ViewEvent.STOP, {id:id, client:client, version:version})); |
|---|
| 210 | } |
|---|
| 211 | |
|---|
| 212 | private function viewVolume(evt:ViewEvent):void { |
|---|
| 213 | viewEventDispatcher.dispatchEvent(new com.jeroenwijering.events.ViewEvent(com.jeroenwijering.events.ViewEvent.VOLUME, {state:evt.data, id:id, client:client, version:version})); |
|---|
| 214 | controllerEventDispatcher.dispatchEvent(new ControllerEvent(ControllerEvent.VOLUME, {percentage:evt.data, id:id, client:client, version:version})); |
|---|
| 215 | } |
|---|
| 216 | |
|---|
| 217 | // Playlist Event Handlers |
|---|
| 218 | |
|---|
| 219 | private function playlistItem(evt:PlaylistEvent):void { |
|---|
| 220 | controllerEventDispatcher.dispatchEvent(new ControllerEvent(ControllerEvent.ITEM, {index:_player.playlist.currentIndex, id:id, client:client, version:version})); |
|---|
| 221 | } |
|---|
| 222 | |
|---|
| 223 | private function playlistLoad(evt:PlaylistEvent):void { |
|---|
| 224 | controllerEventDispatcher.dispatchEvent(new ControllerEvent(ControllerEvent.PLAYLIST, {playlist:playlistToArray(_player.playlist), id:id, client:client, version:version})); |
|---|
| 225 | } |
|---|
| 226 | |
|---|
| 227 | |
|---|
| 228 | // Listeners |
|---|
| 229 | |
|---|
| 230 | public override function addModelListener(type:String, listener:Function):void { |
|---|
| 231 | modelEventDispatcher.addEventListener(type, listener); |
|---|
| 232 | } |
|---|
| 233 | public override function removeModelListener(type:String, listener:Function):void { |
|---|
| 234 | modelEventDispatcher.removeEventListener(type, listener); |
|---|
| 235 | } |
|---|
| 236 | |
|---|
| 237 | public override function addViewListener(type:String, listener:Function):void { |
|---|
| 238 | viewEventDispatcher.addEventListener(type, listener); |
|---|
| 239 | } |
|---|
| 240 | public override function removeViewListener(type:String, listener:Function):void { |
|---|
| 241 | viewEventDispatcher.removeEventListener(type, listener); |
|---|
| 242 | } |
|---|
| 243 | |
|---|
| 244 | public override function addControllerListener(type:String, listener:Function):void { |
|---|
| 245 | controllerEventDispatcher.addEventListener(type, listener); |
|---|
| 246 | } |
|---|
| 247 | public override function removeControllerListener(type:String, listener:Function):void { |
|---|
| 248 | controllerEventDispatcher.removeEventListener(type, listener); |
|---|
| 249 | } |
|---|
| 250 | |
|---|
| 251 | // Event "dispatcher" |
|---|
| 252 | |
|---|
| 253 | public override function sendEvent(typ:String, prm:Object=undefined) : void { |
|---|
| 254 | Logger.log("V4 emulator sending event: " + typ + " " + Strings.print_r(prm)); |
|---|
| 255 | switch (typ) { |
|---|
| 256 | case com.jeroenwijering.events.ViewEvent.FULLSCREEN: |
|---|
| 257 | _player.fullscreen = prm; |
|---|
| 258 | break; |
|---|
| 259 | case com.jeroenwijering.events.ViewEvent.ITEM: |
|---|
| 260 | _player.playlistItem(Number(prm)); |
|---|
| 261 | break; |
|---|
| 262 | case com.jeroenwijering.events.ViewEvent.LINK: |
|---|
| 263 | _player.link(Number(prm)); |
|---|
| 264 | break; |
|---|
| 265 | case com.jeroenwijering.events.ViewEvent.LOAD: |
|---|
| 266 | _player.load(prm); |
|---|
| 267 | break; |
|---|
| 268 | case com.jeroenwijering.events.ViewEvent.MUTE: |
|---|
| 269 | if (prm != null && prm != "") { |
|---|
| 270 | _player.mute = (prm != "false" && prm != 0); |
|---|
| 271 | } else { |
|---|
| 272 | _player.mute = !_player.mute; |
|---|
| 273 | } |
|---|
| 274 | break; |
|---|
| 275 | case com.jeroenwijering.events.ViewEvent.NEXT: |
|---|
| 276 | _player.playlistNext(); |
|---|
| 277 | break; |
|---|
| 278 | case com.jeroenwijering.events.ViewEvent.PLAY: |
|---|
| 279 | if (prm == null || prm == "") { |
|---|
| 280 | if (_player.state == PlayerState.PAUSED || _player.state == PlayerState.IDLE) { |
|---|
| 281 | prm = "true"; |
|---|
| 282 | } else { |
|---|
| 283 | prm = "false"; |
|---|
| 284 | } |
|---|
| 285 | } |
|---|
| 286 | if (prm != null && Strings.serialize(prm.toString()) == false) { |
|---|
| 287 | _player.pause(); |
|---|
| 288 | } else { |
|---|
| 289 | _player.play(); |
|---|
| 290 | } |
|---|
| 291 | break; |
|---|
| 292 | case com.jeroenwijering.events.ViewEvent.PREV: |
|---|
| 293 | _player.playlistPrev(); |
|---|
| 294 | break; |
|---|
| 295 | case com.jeroenwijering.events.ViewEvent.REDRAW: |
|---|
| 296 | _player.redraw(); |
|---|
| 297 | break; |
|---|
| 298 | case com.jeroenwijering.events.ViewEvent.SEEK: |
|---|
| 299 | _player.seek(Number(prm)); |
|---|
| 300 | break; |
|---|
| 301 | case com.jeroenwijering.events.ViewEvent.STOP: |
|---|
| 302 | _player.stop(); |
|---|
| 303 | break; |
|---|
| 304 | case com.jeroenwijering.events.ViewEvent.TRACE: |
|---|
| 305 | Logger.log(prm); |
|---|
| 306 | break; |
|---|
| 307 | case com.jeroenwijering.events.ViewEvent.VOLUME: |
|---|
| 308 | _player.volume(Number(prm)); |
|---|
| 309 | break; |
|---|
| 310 | } |
|---|
| 311 | } |
|---|
| 312 | |
|---|
| 313 | public override function get config():Object { |
|---|
| 314 | var cfg:Object = {}; |
|---|
| 315 | var descType:XML = describeType(_player.config) |
|---|
| 316 | for each (var i:String in descType.accessor.@name) { |
|---|
| 317 | if (_player.config[i] != null) { |
|---|
| 318 | cfg[i] = Strings.serialize(_player.config[i].toString()); |
|---|
| 319 | } |
|---|
| 320 | } |
|---|
| 321 | |
|---|
| 322 | for each (var j:String in _player.config.pluginIds) { |
|---|
| 323 | var pluginConfig:PluginConfig = _player.config.pluginConfig(j); |
|---|
| 324 | for (var k:String in pluginConfig){ |
|---|
| 325 | cfg[j+"."+k] = pluginConfig[k]; |
|---|
| 326 | } |
|---|
| 327 | } |
|---|
| 328 | |
|---|
| 329 | switch(_player.state) { |
|---|
| 330 | case PlayerState.BUFFERING: |
|---|
| 331 | cfg['state'] = ModelStates.BUFFERING; |
|---|
| 332 | break; |
|---|
| 333 | case PlayerState.PLAYING: |
|---|
| 334 | cfg['state'] = ModelStates.PLAYING; |
|---|
| 335 | break; |
|---|
| 336 | case PlayerState.PAUSED: |
|---|
| 337 | cfg['state'] = ModelStates.PAUSED; |
|---|
| 338 | break; |
|---|
| 339 | case PlayerState.IDLE: |
|---|
| 340 | if (_player.playlist.currentIndex > 0 && _player.playlist.currentIndex == (_player.playlist.length-1)) { |
|---|
| 341 | cfg['state'] = ModelStates.COMPLETED; |
|---|
| 342 | } else { |
|---|
| 343 | cfg['state'] = ModelStates.IDLE; |
|---|
| 344 | } |
|---|
| 345 | break; |
|---|
| 346 | } |
|---|
| 347 | |
|---|
| 348 | cfg['fullscreen'] = _player.fullscreen; |
|---|
| 349 | cfg['version'] = _player.version; |
|---|
| 350 | cfg['item'] = _player.playlist.currentIndex; |
|---|
| 351 | cfg['level'] = _player.playlist.currentItem ? _player.playlist.currentItem.currentLevel : 0; |
|---|
| 352 | |
|---|
| 353 | return cfg; |
|---|
| 354 | } |
|---|
| 355 | |
|---|
| 356 | public override function get playlist():Array { |
|---|
| 357 | return playlistToArray(_player.playlist); |
|---|
| 358 | } |
|---|
| 359 | |
|---|
| 360 | private function playlistToArray(list:IPlaylist):Array { |
|---|
| 361 | var arry:Array = []; |
|---|
| 362 | |
|---|
| 363 | for (var i:Number=0; i < list.length; i++) { |
|---|
| 364 | arry.push(playlistItemToObject(list.getItemAt(i))); |
|---|
| 365 | } |
|---|
| 366 | |
|---|
| 367 | return arry; |
|---|
| 368 | } |
|---|
| 369 | |
|---|
| 370 | private function playlistItemToObject(item:PlaylistItem):Object { |
|---|
| 371 | var obj:Object = { |
|---|
| 372 | 'author': item.author, |
|---|
| 373 | 'date': item.date, |
|---|
| 374 | 'description': item.description, |
|---|
| 375 | 'duration': item.duration, |
|---|
| 376 | 'file': item.file, |
|---|
| 377 | 'image': item.image, |
|---|
| 378 | 'link': item.link, |
|---|
| 379 | 'mediaid': item.mediaid, |
|---|
| 380 | 'start': item.start, |
|---|
| 381 | 'streamer': item.streamer, |
|---|
| 382 | 'tags': item.tags, |
|---|
| 383 | 'title': item.title, |
|---|
| 384 | 'type': item.provider |
|---|
| 385 | }; |
|---|
| 386 | |
|---|
| 387 | for (var i:String in item) { |
|---|
| 388 | if (i.indexOf(".") < 0) { |
|---|
| 389 | obj[i] = item[i]; |
|---|
| 390 | } |
|---|
| 391 | } |
|---|
| 392 | |
|---|
| 393 | if (item.levels.length > 0) { |
|---|
| 394 | obj['levels'] = []; |
|---|
| 395 | for each (var level:PlaylistItemLevel in item.levels) { |
|---|
| 396 | obj['levels'].push({url:level.file, bitrate:level.bitrate, width:level.width}); |
|---|
| 397 | } |
|---|
| 398 | } |
|---|
| 399 | |
|---|
| 400 | return obj; |
|---|
| 401 | } |
|---|
| 402 | |
|---|
| 403 | public override function getPluginConfig(plugin:Object):Object { |
|---|
| 404 | if (plugin is IPlugin) { |
|---|
| 405 | return _player.config.pluginConfig((plugin as IPlugin).id) |
|---|
| 406 | } else if (plugin is V4Plugin) { |
|---|
| 407 | return _player.config.pluginConfig((plugin as V4Plugin).pluginId); |
|---|
| 408 | } else if ((plugin as DisplayObject).parent is V4Plugin) { |
|---|
| 409 | return _player.config.pluginConfig((plugin.parent as V4Plugin).pluginId); |
|---|
| 410 | } else if (plugin is IDockComponent) { |
|---|
| 411 | return _player.config.pluginConfig('dock'); |
|---|
| 412 | } else if (plugin is IDisplayComponent) { |
|---|
| 413 | return _player.config.pluginConfig('display'); |
|---|
| 414 | } else if (plugin is IControlbarComponent) { |
|---|
| 415 | return _player.config.pluginConfig('controlbar'); |
|---|
| 416 | } else if (plugin is IPlaylistComponent) { |
|---|
| 417 | return _player.config.pluginConfig('playlist'); |
|---|
| 418 | } else { |
|---|
| 419 | return new PluginConfig(''); |
|---|
| 420 | } |
|---|
| 421 | } |
|---|
| 422 | |
|---|
| 423 | public function resize(width:Number, height:Number):void { |
|---|
| 424 | viewRedraw(width, height); |
|---|
| 425 | } |
|---|
| 426 | |
|---|
| 427 | public override function getPlugin(plugin:String):Object { |
|---|
| 428 | var result:Object; |
|---|
| 429 | switch (plugin){ |
|---|
| 430 | case 'dock': |
|---|
| 431 | result = _player.controls.dock as Object; |
|---|
| 432 | break; |
|---|
| 433 | case 'controlbar': |
|---|
| 434 | result = _player.controls.controlbar as Object; |
|---|
| 435 | break; |
|---|
| 436 | case 'display': |
|---|
| 437 | result = _player.controls.display as Object; |
|---|
| 438 | break; |
|---|
| 439 | case 'playlist': |
|---|
| 440 | result = _player.controls.playlist as Object; |
|---|
| 441 | break; |
|---|
| 442 | default: |
|---|
| 443 | // Backwards compatibility for 4.x plugins |
|---|
| 444 | try { |
|---|
| 445 | result = (_player as Object).getPlugin(plugin); |
|---|
| 446 | } catch (e:Error) {} |
|---|
| 447 | } |
|---|
| 448 | return result; |
|---|
| 449 | } |
|---|
| 450 | } |
|---|
| 451 | } |
|---|