Changeset 396


Ignore:
Timestamp:
10/05/09 21:54:05 (4 years ago)
Author:
pablo
Message:

Implemented clone() on all custom events.
Stretch media to config.stretching
PlayerReady from JavascriptAPI.as
config.file => config.playlist if file has .xml suffix
PluginConfig uses dynamic properties
V4ControlBar dispatches V5 view events
Media placed on stage!

Location:
trunk/fl5
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/fl5/src/com/longtailvideo/jwplayer/controller/Controller.as

    r395 r396  
    11package com.longtailvideo.jwplayer.controller { 
    22        import com.longtailvideo.jwplayer.events.GlobalEventDispatcher; 
     3        import com.longtailvideo.jwplayer.events.MediaEvent; 
    34        import com.longtailvideo.jwplayer.events.PlayerEvent; 
    45        import com.longtailvideo.jwplayer.events.PlaylistEvent; 
     6        import com.longtailvideo.jwplayer.events.ViewEvent; 
    57        import com.longtailvideo.jwplayer.model.Model; 
    68        import com.longtailvideo.jwplayer.model.PlaylistItem; 
     
    1719        import flash.net.URLRequest; 
    1820        import flash.net.navigateToURL; 
    19         import com.longtailvideo.jwplayer.events.MediaEvent; 
    2021 
    2122        /** 
     
    5051                /** File extensions of all supported mediatypes. **/ 
    5152                private var extensions:Object = { 
    52                         '3g2':'video', 
    53                         '3gp':'video', 
    54                         'aac':'video', 
    55                         'f4b':'video', 
    56                         'f4p':'video', 
    57                         'f4v':'video', 
    58                         'flv':'video', 
    59                         'gif':'image', 
    60                         'jpg':'image', 
    61                         'jpeg':'image', 
    62                         'm4a':'video', 
    63                         'm4v':'video', 
    64                         'mov':'video', 
    65                         'mp3':'sound', 
    66                         'mp4':'video', 
    67                         'png':'image', 
    68                         'rbs':'sound', 
    69                         'sdp':'video', 
    70                         'swf':'image', 
    71                         'vp6':'video' 
    72                 }; 
     53                                '3g2':'video', 
     54                                '3gp':'video', 
     55                                'aac':'video', 
     56                                'f4b':'video', 
     57                                'f4p':'video', 
     58                                'f4v':'video', 
     59                                'flv':'video', 
     60                                'gif':'image', 
     61                                'jpg':'image', 
     62                                'jpeg':'image', 
     63                                'm4a':'video', 
     64                                'm4v':'video', 
     65                                'mov':'video', 
     66                                'mp3':'sound', 
     67                                'mp4':'video', 
     68                                'png':'image', 
     69                                'rbs':'sound', 
     70                                'sdp':'video', 
     71                                'swf':'image', 
     72                                'vp6':'video' 
     73                        }; 
    7374 
    7475                /** A list with legacy CDN classes that are now redirected to buit-in ones. **/ 
    7576                private var cdns:Object = { 
    76                         bitgravity:     {'http.startparam':'starttime', provider:'http'}, 
    77                         edgecast:       {'http.startparam':'ec_seek',   provider:'http'}, 
    78                         flvseek:        {'http.startparam':'fs',                provider:'http'}, 
    79                         highwinds:      {'rtmp.loadbalance':true,               provider:'rtmp'}, 
    80                         lighttpd:       {'http.startparam':'start',     provider:'http'}, 
    81                         vdox:           {'rtmp.loadbalance':true,               provider:'rtmp'} 
    82                 }; 
     77                                bitgravity:{'http.startparam':'starttime', provider:'http'}, 
     78                                edgecast:{'http.startparam':'ec_seek', provider:'http'}, 
     79                                flvseek:{'http.startparam':'fs', provider:'http'}, 
     80                                highwinds:{'rtmp.loadbalance':true, provider:'rtmp'}, 
     81                                lighttpd:{'http.startparam':'start', provider:'http'}, 
     82                                vdox:{'rtmp.loadbalance':true, provider:'rtmp'} 
     83                        }; 
    8384 
    8485                public function Controller(player:Player, model:Model, view:View) { 
     
    106107 
    107108                private function addViewListeners():void { 
    108  
     109                        _view.addEventListener(ViewEvent.JWPLAYER_VIEW_PLAY, playHandler); 
     110                        _view.addEventListener(ViewEvent.JWPLAYER_VIEW_STOP, stopHandler); 
     111                } 
     112 
     113                private function playHandler(evt:Event):void { 
     114                        if (_model.playlist.currentItem) { 
     115                                switch (_player.state) { 
     116                                        case PlayerState.IDLE: 
     117                                                load(_model.playlist.currentItem); 
     118                                                break; 
     119                                        case PlayerState.PAUSED: 
     120                                                _model.media.play(); 
     121                                                break; 
     122                                } 
     123                        } 
     124                } 
     125 
     126                private function stopHandler(evt:ViewEvent):void { 
     127                        switch (_player.state) { 
     128                                case PlayerState.BUFFERING: 
     129                                case PlayerState.PLAYING: 
     130                                        _model.media.stop(); 
     131                                        break; 
     132                        } 
    109133                } 
    110134 
     
    116140 
    117141                private function setupComplete(evt:Event):void { 
    118                         trace("Setup complete"); 
     142                        dispatchEvent(new PlayerEvent(PlayerEvent.JWPLAYER_READY)); 
    119143                        RootReference.stage.dispatchEvent(new Event(Event.RESIZE)); 
     144                        loadFirstItem(); 
    120145                } 
    121146 
     
    123148                        // This stuff moved to playlist item handler 
    124149                } 
    125                  
     150 
    126151                private function playlistItemHandler(evt:PlaylistEvent):void { 
    127152                        var item:PlaylistItem = _model.playlist.currentItem; 
    128153                        if (item.provider) { 
    129                                  
     154 
    130155                                // Backwards compatibility for CDNs in the 'type' flashvar. 
    131156                                if (cdns.hasOwnProperty(item.provider)) { 
    132157                                        _model.config.setConfig(cdns[item.provider]); 
    133158                                } 
    134                                          
     159 
    135160                                // If the model doesn't have an instance of the provider, load & instantiate it 
    136161                                if (!_model.hasMediaProvider(item.provider)) { 
     
    141166                                        return; 
    142167                                } 
    143                         } 
    144                          
    145                         load(_model.playlist.currentItem); 
    146                 } 
    147                  
     168                                 
     169                                _model.setActiveMediaProvider(item.provider); 
     170                        } 
     171 
     172                        if (_player.config.autostart) {  
     173                                load(_model.playlist.currentItem);  
     174                        } 
     175                } 
     176 
    148177                private function mediaSourceLoaded(evt:Event):void { 
    149178                        var loader:MediaProviderLoader = evt.target as MediaProviderLoader; 
    150179                        _model.setMediaProvider(_model.playlist.currentItem.provider, loader.loadedSource); 
     180                        _model.setActiveMediaProvider(_model.playlist.currentItem.provider); 
    151181                        load(_model.playlist.currentItem); 
    152182                } 
    153                  
     183 
    154184                private function errorHandler(evt:ErrorEvent):void { 
    155185                        errorState(evt.text); 
     
    334364                        return false; 
    335365                } 
    336                  
     366 
    337367                private function lockHandler(evt:MediaEvent):void { 
    338368                        _model.media.play(); 
     
    361391                        return false; 
    362392                } 
     393                 
     394                private function loadFirstItem():void { 
     395//                      if (_model.playlist.currentItem) { 
     396//                              load(_model.playlist.currentItem); 
     397//                      }        
     398                } 
     399                 
    363400 
    364401        } 
  • trunk/fl5/src/com/longtailvideo/jwplayer/controller/PlayerSetup.as

    r393 r396  
    7575                        tasker.queueTask(initPlugins); 
    7676                        tasker.queueTask(setupJS); 
    77                         tasker.queueTask(beginAutostart); 
    7877                         
    7978                        tasker.runTasks(); 
     
    203202                } 
    204203 
    205                 private function beginAutostart():void { 
    206                         tasker.success(); 
    207                 } 
    208                  
    209                  
    210204        } 
    211205} 
  • trunk/fl5/src/com/longtailvideo/jwplayer/events/MediaEvent.as

    r395 r396  
    11package com.longtailvideo.jwplayer.events { 
     2        import flash.events.Event; 
    23 
    34        /** 
     
    170171                        super(type); 
    171172                } 
     173                 
     174                public override function clone():Event { 
     175                        var evt:MediaEvent = new MediaEvent(this.type); 
     176                        evt.bufferPercent = this.bufferPercent; 
     177                        evt.duration = this.duration; 
     178                        evt.metadata = this.metadata; 
     179                        evt.position = this.position; 
     180                        evt.volume = this.volume; 
     181                        evt.mute = this.mute; 
     182                        return evt; 
     183                } 
    172184        } 
    173185} 
  • trunk/fl5/src/com/longtailvideo/jwplayer/events/PlayerEvent.as

    r393 r396  
    8787                } 
    8888                 
     89                public override function toString():String { 
     90                        var superString:String = super.toString(); 
     91                        return superString.substr(0, superString.length-1)  
     92                                + " id=" + id  
     93                                + " client=" + client  
     94                                + " version=" + version 
     95                                + " message=" + message 
     96                                + "]"; 
     97                }  
     98                 
     99                public override function clone():Event { 
     100                        return new PlayerEvent(this.type, this.message); 
     101                } 
     102                 
    89103        } 
    90104} 
  • trunk/fl5/src/com/longtailvideo/jwplayer/events/PlayerStateEvent.as

    r380 r396  
    11package com.longtailvideo.jwplayer.events { 
     2        import flash.events.Event; 
    23 
    34        public class PlayerStateEvent extends PlayerEvent { 
     
    1213                        this.oldstate = oldState; 
    1314                } 
     15                 
     16                public override function clone():Event { 
     17                        return new PlayerStateEvent(this.type, this.newstate, this.oldstate); 
     18                } 
    1419        } 
    1520} 
  • trunk/fl5/src/com/longtailvideo/jwplayer/events/PlaylistEvent.as

    r292 r396  
    11package com.longtailvideo.jwplayer.events { 
     2        import flash.events.Event; 
    23         
    34 
     
    4445                } 
    4546                 
     47                public override function clone() : Event { 
     48                        return new PlaylistEvent(this.type); 
     49                } 
     50                 
    4651        } 
    4752} 
  • trunk/fl5/src/com/longtailvideo/jwplayer/events/ViewEvent.as

    r395 r396  
    11package com.longtailvideo.jwplayer.events { 
     2        import flash.events.Event; 
    23 
    34        public class ViewEvent extends PlayerEvent { 
     
    129130                } 
    130131                 
     132                public override function clone():Event { 
     133                        return new ViewEvent(this.type, this.data); 
     134                } 
     135                 
    131136        } 
    132137} 
  • trunk/fl5/src/com/longtailvideo/jwplayer/media/MediaProvider.as

    r395 r396  
    33        import com.longtailvideo.jwplayer.events.IGlobalEventDispatcher; 
    44        import com.longtailvideo.jwplayer.events.MediaEvent; 
     5        import com.longtailvideo.jwplayer.events.PlayerEvent; 
    56        import com.longtailvideo.jwplayer.events.PlayerStateEvent; 
    67        import com.longtailvideo.jwplayer.model.PlayerConfig; 
    78        import com.longtailvideo.jwplayer.model.PlaylistItem; 
     9        import com.longtailvideo.jwplayer.player.PlayerState; 
     10        import com.longtailvideo.jwplayer.utils.Stretcher; 
    811         
    912        import flash.display.DisplayObject; 
     13        import flash.display.Loader; 
    1014        import flash.display.Sprite; 
    1115        import flash.events.Event; 
    12         import com.longtailvideo.jwplayer.player.PlayerState; 
     16        import flash.events.IOErrorEvent; 
     17        import flash.net.URLRequest; 
    1318         
    14          
    1519        /** 
    1620         * Fired when a portion of the current media has been loaded into the buffer. 
     
    2226         * Fired when the buffer is full. 
    2327         * 
    24          * @eventType com.longtailvideo.jwplayer.events.MediaEvent.JWPLAYER_MEDIA_BUFFER 
     28         * @eventType com.longtailvideo.jwplayer.events.MediaEvent.JWPLAYER_MEDIA_BUFFER_FULL 
    2529         */ 
    2630        [Event(name="jwplayerMediaBufferFull", type="com.longtailvideo.jwplayer.events.MediaEvent")] 
     
    7175                protected var _dispatcher:GlobalEventDispatcher; 
    7276                 
    73                  
    74                 public function MediaProvider(){                 
     77                public function MediaProvider(){ 
     78                        _dispatcher = new GlobalEventDispatcher(); 
    7579                } 
    7680                 
    7781                public function initializeMediaProvider(cfg:PlayerConfig):void { 
    7882                        _config = cfg; 
    79                         _dispatcher = new GlobalEventDispatcher(); 
    8083                        _state = PlayerState.IDLE; 
    8184                } 
    82                  
    8385                 
    8486                /** 
     
    144146                 
    145147                /** Graphical representation of media **/ 
    146                 public function display():DisplayObject { 
     148                public function get display():DisplayObject { 
    147149                        return _media; 
    148150                } 
     
    190192                 * @param height        The new height of the display. 
    191193                 **/ 
    192                   
    193194                 public function resize(width:Number, height:Number):void { 
    194                         _media.width = width; 
    195                         _media.height = height; 
     195                        if (_media) { 
     196                                Stretcher.stretch(_media, width, height, _config.stretching); 
     197                        } 
     198                         
    196199                 } 
    197200                 
     
    209212                        } 
    210213                } 
    211  
    212214                 
    213215                /** 
     
    274276                        return super.dispatchEvent(event); 
    275277                } 
     278                 
    276279        } 
    277280} 
  • trunk/fl5/src/com/longtailvideo/jwplayer/model/PlayerConfig.as

    r395 r396  
    11package com.longtailvideo.jwplayer.model { 
    22        import com.longtailvideo.jwplayer.plugins.PluginConfig; 
     3        import com.longtailvideo.jwplayer.utils.Strings; 
    34        import com.longtailvideo.jwplayer.utils.TypeChecker; 
    45         
     
    4647                private var _pluginConfig:Object        = {}; 
    4748                 
     49                private var _playerready:String         = ""; 
     50                 
    4851                public function PlayerConfig(playlist:Playlist):void { 
    4952                        getCookiedParams(); 
     
    6063                        for (var item:String in config) { 
    6164                                if (newItem.hasOwnProperty(item)) { 
    62                                         if (_list.length > 0) { 
     65                                        if (item == "file" && Strings.extension(config[item]) == "xml") { 
     66                                                setProperty("playlist", config[item]);                                   
     67                                        } else if (_list.length > 0) { 
    6368                                                _list.currentItem[item] = config[item]; 
    6469                                        } else { 
     
    311316                public function get plugins():String { return _plugins; } 
    312317                public function set plugins(x:String):void { _plugins = x; } 
     318 
     319                /** Javascript player ready callback handlers **/                
     320                public function get playerready():String { return _playerready; } 
     321                public function set playerready(x:String):void { _playerready = x; } 
    313322                 
    314323                /** 
  • trunk/fl5/src/com/longtailvideo/jwplayer/model/Playlist.as

    r359 r396  
    11package com.longtailvideo.jwplayer.model { 
    22        import com.longtailvideo.jwplayer.events.GlobalEventDispatcher; 
     3        import com.longtailvideo.jwplayer.events.PlayerEvent; 
    34        import com.longtailvideo.jwplayer.events.PlaylistEvent; 
    45        import com.longtailvideo.jwplayer.parsers.IPlaylistParser; 
     
    9091                        list = newList; 
    9192                        index = newList.length > 0 ? 0 : -1; 
    92  
    93                         dispatchEvent(new PlaylistEvent(PlaylistEvent.JWPLAYER_PLAYLIST_LOADED)); 
     93         
     94                        if (index >= 0) { 
     95                                dispatchEvent(new PlaylistEvent(PlaylistEvent.JWPLAYER_PLAYLIST_LOADED)); 
     96                                dispatchEvent(new PlaylistEvent(PlaylistEvent.JWPLAYER_PLAYLIST_ITEM)); 
     97                        } else { 
     98                                dispatchEvent(new PlayerEvent(PlayerEvent.JWPLAYER_ERROR, "Loaded playlist is empty")); 
     99                        } 
     100                         
    94101                        return;  
    95102                } 
     
    186193                 
    187194                public function get currentItem():PlaylistItem { 
    188                         return getItemAt(index); 
     195                        return index >= 0 ? getItemAt(index) : null; 
    189196                } 
    190197                 
  • trunk/fl5/src/com/longtailvideo/jwplayer/player/Player.as

    r393 r396  
    66        import com.longtailvideo.jwplayer.model.Playlist; 
    77        import com.longtailvideo.jwplayer.plugins.IPlugin; 
     8        import com.longtailvideo.jwplayer.utils.Logger; 
    89        import com.longtailvideo.jwplayer.utils.RootReference; 
    910        import com.longtailvideo.jwplayer.view.ISkin; 
     
    5253                        } 
    5354                        model = new Model(); 
    54                         view = new View(this); 
     55                        view = new View(this, model); 
    5556                        controller = new Controller(this, model, view); 
    5657 
     
    6061 
    6162                        // Initialize V4 "simulator" singleton 
    62                         new PlayerV4Emulation(this); 
     63                        var emu:PlayerV4Emulation = new PlayerV4Emulation(this); 
     64                        var jsAPI:JavascriptAPI = new JavascriptAPI(this); 
     65 
     66                        Logger.output = Logger.CONSOLE; 
    6367 
    6468                        controller.setupPlayer(); 
     
    7074                 */ 
    7175                protected function forward(evt:PlayerEvent):void { 
     76                        Logger.log(evt.toString(), evt.type); 
    7277                        dispatchEvent(evt); 
    7378                } 
  • trunk/fl5/src/com/longtailvideo/jwplayer/player/PlayerV4Emulation.as

    r395 r396  
    4646                        if (!initialized) { 
    4747                                initialized = true; 
     48                                 
     49                                viewEventDispatcher = new EventDispatcher(); 
     50                                modelEventDispatcher = new EventDispatcher(); 
     51                                controllerEventDispatcher = new EventDispatcher(); 
     52                                 
    4853                                _player = player; 
    4954                                _player.addEventListener(PlayerEvent.JWPLAYER_READY, playerReady); 
    50                                 instance = new PlayerV4Emulation(player); 
     55                                instance = this; 
    5156                        } 
    5257                } 
     
    7176                        var v:ControlBarComponent; 
    7277                        var c:Controller 
     78                         
     79                        _player.addEventListener(PlayerEvent.JWPLAYER_ERROR, errorHandler); 
    7380                         
    7481                        _player.addEventListener(MediaEvent.JWPLAYER_MEDIA_BUFFER, mediaBuffer); 
     
    93100                        _player.playlist.addEventListener(PlaylistEvent.JWPLAYER_PLAYLIST_ITEM, playlistItem); 
    94101                        _player.playlist.addEventListener(PlaylistEvent.JWPLAYER_PLAYLIST_LOADED, playlistLoad); 
     102                } 
     103                 
     104                // Player Event Handlers 
     105                 
     106                private function errorHandler(evt:PlayerEvent):void { 
     107                        controllerEventDispatcher.dispatchEvent(new ControllerEvent(ControllerEvent.ERROR, {message:evt.message, id:id, client:client, version:version})); 
    95108                } 
    96109                 
  • trunk/fl5/src/com/longtailvideo/jwplayer/plugins/Display.as

    r395 r396  
    11package com.longtailvideo.jwplayer.plugins { 
    2         import com.longtailvideo.jwplayer.events.MediaEvent; 
    3         import com.longtailvideo.jwplayer.events.PlayerStateEvent; 
    4         import com.longtailvideo.jwplayer.events.PlaylistEvent; 
    52        import com.longtailvideo.jwplayer.player.Player; 
    63         
     4        import flash.display.DisplayObject; 
    75        import flash.events.Event; 
    8         import flash.display.DisplayObject; 
    96         
    107         
  • trunk/fl5/src/com/longtailvideo/jwplayer/plugins/PluginConfig.as

    r282 r396  
    55                private var _name:String; 
    66 
    7                 public var width:Number; 
    8                 public var height:Number; 
    9  
    107                public function PluginConfig(pluginName:String) { 
    118                        this._name = pluginName; 
     9                        this['width'] = 0; 
     10                        this['height'] = 0; 
    1211                } 
    1312                 
  • trunk/fl5/src/com/longtailvideo/jwplayer/utils/Logger.as

    r386 r396  
    4848                                Logger.object(message, type); 
    4949                        } 
    50                 }; 
     50                } 
    5151                 
    5252                 
     
    5757                        txt += ')'; 
    5858                        Logger.send(txt); 
    59                 }; 
     59                } 
    6060                 
    6161                 
     
    7070                                CONNECTION.addEventListener(StatusEvent.STATUS, Logger.status); 
    7171                        } 
    72                         SharedObject.getLocal('com.jeroenwijering', '/').data['debug'] = put; 
     72                        SharedObject.getLocal('com.longtailvideo.jwplayer', '/').data['debug'] = put; 
    7373                        Logger._output = put; 
    74                 }; 
     74                } 
    7575                 
    7676                 
     
    8282                public static function get output():String { 
    8383                        return Logger._output; 
    84                 }; 
     84                } 
    8585                 
    8686                 
     
    103103                                        break; 
    104104                        } 
    105                 }; 
     105                } 
    106106                 
    107107                 
    108108                /** Manage the status call of localconnection. **/ 
    109109                private static function status(evt:StatusEvent):void { 
    110                 }; 
     110                } 
    111111        } 
    112112} 
  • trunk/fl5/src/com/longtailvideo/jwplayer/view/V4ControlBarComponent.as

    r395 r396  
    3838                private var light:ColorTransform; 
    3939                /** The actions for all controlbar buttons. **/ 
    40                 private var BUTTONS:Object = {playButton: 'PLAY', pauseButton: 'PLAY', stopButton: 'STOP', prevButton: 'PREV', nextButton: 'NEXT', linkButton: 'LINK', fullscreenButton: 'FULLSCREEN', normalscreenButton: 'FULLSCREEN', muteButton: 'MUTE', unmuteButton: 'MUTE'} 
     40                private var BUTTONS:Object; 
    4141                /** The actions for all sliders **/ 
    4242                private var SLIDERS:Object = {timeSlider: ViewEvent.JWPLAYER_VIEW_SEEK, volumeSlider: ViewEvent.JWPLAYER_VIEW_VOLUME} 
     
    4949                public function V4ControlBarComponent(player:Player) { 
    5050                        super(player); 
     51 
     52                        BUTTONS = { 
     53                                playButton: ViewEvent.JWPLAYER_VIEW_PLAY,  
     54                                pauseButton: ViewEvent.JWPLAYER_VIEW_PAUSE,  
     55                                stopButton: ViewEvent.JWPLAYER_VIEW_STOP,  
     56                                prevButton: ViewEvent.JWPLAYER_VIEW_PREV,  
     57                                nextButton: ViewEvent.JWPLAYER_VIEW_NEXT,  
     58                                linkButton: 'LINK',  
     59                                fullscreenButton: ViewEvent.JWPLAYER_VIEW_FULLSCREEN,  
     60                                normalscreenButton: ViewEvent.JWPLAYER_VIEW_FULLSCREEN,  
     61                                muteButton: ViewEvent.JWPLAYER_VIEW_MUTE,  
     62                                unmuteButton: ViewEvent.JWPLAYER_VIEW_MUTE 
     63                        }; 
     64 
    5165                        var temp:Sprite = player.skin.getSWFSkin(); 
    5266                        skin = player.skin.getSWFSkin().getChildByName('controlbar') as Sprite; 
     
    158172                private function clickHandler(evt:MouseEvent):void { 
    159173                        var act:String = BUTTONS[evt.target.name]; 
     174                        var data:Object = null; 
    160175                        if (blocking != true || act == "FULLSCREEN" || act == "MUTE") { 
    161                                 dispatchEvent(new ViewEvent(act)); 
     176                                switch (act) { 
     177                                        case ViewEvent.JWPLAYER_VIEW_PLAY: 
     178                                        case ViewEvent.JWPLAYER_VIEW_PAUSE: 
     179                                                data = Boolean(_player.state == PlayerState.IDLE || _player.state == PlayerState.PAUSED); 
     180                                                break; 
     181                                        case ViewEvent.JWPLAYER_VIEW_MUTE: 
     182                                                data = Boolean(!_player.config.mute); 
     183                                                break; 
     184                                } 
     185                                dispatchEvent(new ViewEvent(act, data)); 
    162186                        } 
    163187                } 
     
    301325                /** Clickhandler for all buttons. **/ 
    302326                private function setButtons():void { 
    303                         for (var btn:String in BUTTONS) { 
     327                        for (var btn:String in BUTTONS) { 
    304328                                if (getSkinElement("controlbar", btn)) { 
    305329                                        (getSkinElement("controlbar", btn) as MovieClip).mouseChildren = false; 
     
    415439                                pos = evt.position; 
    416440                        } else if (player.playlist.length > 0) { 
    417                                 dur = player.playlist[player.config.item]['duration']; 
     441                                dur = player.playlist.getItemAt(player.config.item).duration; 
    418442                                pos = 0; 
    419443                        } 
     
    454478                        scrubber.icon.stopDrag(); 
    455479                        if (scrubber.name == 'timeSlider' && player.playlist) { 
    456                                 mpl = player.playlist[player.config.item]['duration']; 
     480                                mpl = player.playlist.getItemAt(player.config.item).duration; 
    457481                        } else if (scrubber.name == 'volumeSlider') { 
    458482                                mpl = 100; 
  • trunk/fl5/src/com/longtailvideo/jwplayer/view/View.as

    r395 r396  
    11package com.longtailvideo.jwplayer.view { 
    22        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; 
    36        import com.longtailvideo.jwplayer.events.PlaylistEvent; 
     7        import com.longtailvideo.jwplayer.model.Model; 
    48        import com.longtailvideo.jwplayer.player.Player; 
     9        import com.longtailvideo.jwplayer.player.PlayerState; 
    510        import com.longtailvideo.jwplayer.plugins.IPlugin; 
    611        import com.longtailvideo.jwplayer.plugins.PluginConfig; 
    712        import com.longtailvideo.jwplayer.utils.RootReference; 
     13        import com.longtailvideo.jwplayer.utils.Stretcher; 
    814         
    915        import flash.display.DisplayObject; 
     16        import flash.display.Loader; 
    1017        import flash.display.MovieClip; 
    1118        import flash.display.Stage; 
     
    1421        import flash.events.ErrorEvent; 
    1522        import flash.events.Event; 
     23        import flash.events.IOErrorEvent; 
     24        import flash.net.URLRequest; 
    1625         
    1726         
    1827        public class View extends GlobalEventDispatcher { 
    1928                private var _player:Player; 
     29                private var _model:Model; 
    2030                private var _skin:ISkin; 
    2131                private var _components:PlayerComponents; 
    2232                private var _fullscreen:Boolean = false; 
    2333                private var stage:Stage; 
     34 
    2435                private var _backgroundLayer:MovieClip; 
    2536                private var _mediaLayer:MovieClip; 
     37                private var _imageLayer:MovieClip; 
    2638                private var _componentsLayer:MovieClip; 
    2739                private var _pluginsLayer:MovieClip;             
    2840                 
    29                 public function View(player:Player) { 
     41                private var _image:Loader; 
     42                 
     43                public function View(player:Player, model:Model) { 
    3044                        _player = player; 
     45                        _model = model; 
     46                         
    3147                        setupLayers(); 
    3248                        RootReference.stage.scaleMode = StageScaleMode.NO_SCALE; 
     
    3450                        RootReference.stage.addEventListener(Event.FULLSCREEN, resizeHandler); 
    3551                        RootReference.stage.addEventListener(Event.RESIZE, resizeHandler); 
    36                         player.addEventListener(PlaylistEvent.JWPLAYER_PLAYLIST_ITEM, playlistHandler); 
    37                 } 
    38                  
    39                  
    40                 private function playlistHandler(evt:PlaylistEvent):void { 
    41  
    42                 } 
     52                        _model.addEventListener(MediaEvent.JWPLAYER_MEDIA_LOADED, mediaLoaded); 
     53                        _model.playlist.addEventListener(PlaylistEvent.JWPLAYER_PLAYLIST_ITEM, itemHandler); 
     54                        _model.addEventListener(PlayerStateEvent.JWPLAYER_PLAYER_STATE, stateHandler); 
     55                } 
     56                 
    4357                 
    4458                private function setupLayers():void { 
     
    4761                        background.name = "background"; 
    4862                        _backgroundLayer.addChildAt(background, 0); 
    49                         background.graphics.beginFill(0,0.5); 
     63                        background.graphics.beginFill(_player.config.backcolor, 1); 
    5064                        background.graphics.drawRect(0,0,1,1); 
    5165                        background.graphics.endFill(); 
     
    5367                        _mediaLayer = setupLayer("media", 1);                    
    5468 
    55                         _componentsLayer = setupLayer("components", 2); 
    56                          
    57                         _pluginsLayer = setupLayer("plugins", 3); 
     69                        _imageLayer = setupLayer("image", 2);                    
     70                        _image = new Loader(); 
     71                        _image.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, imageError); 
     72                        _image.contentLoaderInfo.addEventListener(Event.COMPLETE, imageComplete); 
     73 
     74                        _componentsLayer = setupLayer("components", 3); 
     75                        _pluginsLayer = setupLayer("plugins", 4); 
    5876                } 
    5977                 
     
    6987 
    7088                private function resizeHandler(event:Event):void{ 
    71                         _backgroundLayer.getChildByName("background").width = RootReference.stage.stageWidth; 
    72                         _backgroundLayer.getChildByName("background").height = RootReference.stage.stageHeight; 
    73  
    74                         _components.resize(RootReference.stage.stageWidth,RootReference.stage.stageHeight); 
     89                        var width:Number = RootReference.stage.stageWidth; 
     90                        var height:Number = RootReference.stage.stageHeight; 
     91                        _backgroundLayer.getChildByName("background").width = width; 
     92                        _backgroundLayer.getChildByName("background").height = height; 
     93 
     94                        _components.resize(width, height); 
     95                         
     96                        _player.config.width = width; 
     97                        _player.config.height = height; 
     98                         
     99                        if (_imageLayer.numChildren) { 
     100                                Stretcher.stretch(_image, width, height, _player.config.stretching); 
     101                        } 
     102 
     103                        if (_mediaLayer.numChildren) { 
     104                                _model.media.resize(width, height); 
     105                        } 
    75106                } 
    76107                 
     
    86117                private function setupComponents():void { 
    87118                        _components = new PlayerComponents(_player); 
     119                         
     120                        _components.controlbar.addGlobalListener(forward); 
     121                         
    88122                        _componentsLayer.addChildAt(_components.display as MovieClip, 0); 
    89123                        _componentsLayer.addChildAt(_components.controlbar as MovieClip, 1); 
     124                         
     125                         
     126                         
    90127                        //addToLayer(_playerComponents.controlbar as MovieClip, _components); 
    91128                        //addToStage(_playerComponents.dock, _player.config.width, _player.config.height); 
     
    102139                } 
    103140                 
    104                  
     141                /** Redraws the plugins **/ 
    105142                public function redraw():void { 
    106143                        for (var i:Number=0; i < _pluginsLayer.numChildren; i++) { 
     
    162199                        return _pluginsLayer.getChildByName(name) as IPlugin; 
    163200                } 
     201                 
     202                private function mediaLoaded(evt:MediaEvent):void { 
     203                        while (_mediaLayer.numChildren) { 
     204                                _mediaLayer.removeChildAt(0); 
     205                        } 
     206                        _mediaLayer.addChild(_model.media.display); 
     207                        _model.media.resize(_player.config.width, _player.config.height); 
     208                } 
     209                 
     210                private function itemHandler(evt:PlaylistEvent):void { 
     211                        if (_model.playlist.currentItem && _model.playlist.currentItem.image) { 
     212                                loadImage(_model.playlist.currentItem.image); 
     213                        } 
     214                } 
     215 
     216                private function loadImage(url:String):void { 
     217                        _image.load(new URLRequest(url)); 
     218                } 
     219                 
     220                private function imageComplete(evt:Event):void { 
     221                        while (_imageLayer.numChildren) { _imageLayer.removeChildAt(0); } 
     222                        _imageLayer.addChild(_image); 
     223                        Stretcher.stretch(_image, _player.config.width, _player.config.height, _player.config.stretching); 
     224                } 
     225                 
     226                private function imageError(evt:IOErrorEvent):void { 
     227                        _image = null; 
     228                        dispatchEvent(new PlayerEvent(PlayerEvent.JWPLAYER_ERROR, evt.text));    
     229                } 
     230 
     231                private function stateHandler(evt:PlayerStateEvent):void { 
     232                        switch (evt.newstate) { 
     233                                case PlayerState.IDLE: 
     234                                        _mediaLayer.visible = false; 
     235                                        _imageLayer.visible = true; 
     236                                        break; 
     237                                case PlayerState.PLAYING: 
     238                                        _mediaLayer.visible = true; 
     239                                        _imageLayer.visible = false; 
     240                                        break; 
     241                        } 
     242                } 
     243                 
     244                private function forward(evt:Event):void { 
     245                        dispatchEvent(evt); 
     246                } 
     247 
    164248        } 
    165249} 
  • trunk/fl5/test/tests/media/MediaProviderTestJig.as

    r381 r396  
    7474                 
    7575                private function loadHandler(evt:MediaEvent):void { 
    76                         if (provider.display()) { 
    77                                 RootReference.stage.addChild(provider.display()); 
     76                        if (provider.display) { 
     77                                RootReference.stage.addChild(provider.display); 
    7878                        } 
    7979                        eventHandler(evt); 
     
    158158                 
    159159                protected function hideDisplay():void { 
    160                         if (provider.display()) { 
    161                                 provider.display().visible = false; 
     160                        if (provider.display) { 
     161                                provider.display.visible = false; 
    162162                        } 
    163163                } 
Note: See TracChangeset for help on using the changeset viewer.