Changeset 1228


Ignore:
Timestamp:
08/20/10 19:32:44 (3 years ago)
Author:
pablo
Message:
  • Fixes a problem with locking the player can prevent the playlist item from loading
  • Player now dispatches "jwplayerFullscreen" and "jwplayerResize" events
  • Player implements IGlobalEventDispatcher
  • Player queues up dispatched events sent out before the playerReady JavasScript callback is made


Location:
trunk/fl5
Files:
9 edited

Legend:

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

    r1207 r1228  
    3636         */ 
    3737        [Event(name="jwplayerError", type = "com.longtailvideo.jwplayer.events.PlayerEvent")] 
     38 
     39        /** 
     40         * Sent when the player has been locked 
     41         * 
     42         * @eventType com.longtailvideo.jwplayer.events.PlayerEvent.JWPLAYER_LOCKED 
     43         */ 
     44        [Event(name="jwplayerLocked", type = "com.longtailvideo.jwplayer.events.PlayerEvent")] 
     45 
     46        /** 
     47         * Sent when the player has been unlocked 
     48         * 
     49         * @eventType com.longtailvideo.jwplayer.events.PlayerEvent.JWPLAYER_UNLOCKED 
     50         */ 
     51        [Event(name="jwplayerUnlocked", type = "com.longtailvideo.jwplayer.events.PlayerEvent")] 
     52 
     53        /** 
     54         * Sent when the player has gone into or out of fullscreen mode 
     55         * 
     56         * @eventType com.longtailvideo.jwplayer.events.PlayerEvent.JWPLAYER_FULLSCREEN 
     57         */ 
     58        [Event(name="jwplayerFullscreen", type = "com.longtailvideo.jwplayer.events.PlayerEvent")] 
    3859 
    3960        /** 
     
    283304                                if (!locking && (_lockingResume || _unlockAutostart)) { 
    284305                                        _lockingResume = false; 
     306                                        if (_unlockAndLoad) { 
     307                                                load(_player.playlist.currentItem); 
     308                                                _unlockAndLoad = false; 
     309                                        } 
    285310                                        play(); 
    286311                                        if (_unlockAutostart) { 
    287312                                                _unlockAutostart = false; 
    288                                         } else if (_unlockAndLoad) { 
    289                                                 _unlockAndLoad = false; 
    290313                                        } 
    291314                                } 
     
    626649                        _model.fullscreen = mode; 
    627650                        _view.fullscreen(mode); 
     651                        dispatchEvent(new PlayerEvent(PlayerEvent.JWPLAYER_FULLSCREEN, mode.toString())); 
    628652                        return true; 
    629653                } 
  • trunk/fl5/src/com/longtailvideo/jwplayer/events/PlayerEvent.as

    r843 r1228  
    4242             *          <tr><td><code>client</code></td><td>A string representing the client the player runs in (e.g. FLASH WIN 9,0,115,0).</td></tr> 
    4343             *          <tr><td><code>version</code></td><td>A string representing the major version, minor version and revision number of the player (e.g. 5.0.395).</td></tr> 
    44              *          <tr><td><code>message</code></td><td>Message explaining the cause of the error</td></tr> 
    4544             * </table> 
    4645             *  
     
    6059                 *              <tr><td><code>client</code></td><td>A string representing the client the player runs in (e.g. FLASH WIN 9,0,115,0).</td></tr> 
    6160                 *              <tr><td><code>version</code></td><td>A string representing the major version, minor version and revision number of the player (e.g. 5.0.395).</td></tr> 
    62                  *              <tr><td><code>message</code></td><td>Message explaining the cause of the error</td></tr> 
    6361                 * </table> 
    6462                 *  
     
    7876                 *              <tr><td><code>client</code></td><td>A string representing the client the player runs in (e.g. FLASH WIN 9,0,115,0).</td></tr> 
    7977                 *              <tr><td><code>version</code></td><td>A string representing the major version, minor version and revision number of the player (e.g. 5.0.395).</td></tr> 
    80                  *              <tr><td><code>message</code></td><td>Message explaining the cause of the error</td></tr> 
    8178                 * </table> 
    8279                 *  
     
    8582                 */ 
    8683                public static var JWPLAYER_ERROR:String = "jwplayerError"; 
    87                  
     84 
     85                /** 
     86                 * The PlayerEvent.JWPLAYER_FULLSCREEN constant defines the value of the 
     87                 * <code>type</code> property of the event object 
     88                 * for a <code>jwplayerFullscreen</code> event. 
     89                 * 
     90                 * <table class="innertable"> 
     91                 *              <tr><th>Property</th><th>Value</th></tr> 
     92                 *              <tr><td><code>id</code></td><td>ID of the player in the HTML DOM. Used by javascript to reference the player.</td></tr> 
     93                 *              <tr><td><code>client</code></td><td>A string representing the client the player runs in (e.g. FLASH WIN 9,0,115,0).</td></tr> 
     94                 *              <tr><td><code>version</code></td><td>A string representing the major version, minor version and revision number of the player (e.g. 5.0.395).</td></tr> 
     95                 *              <tr><td><code>message</code></td><td>New fullscreen mode ("true", or "false")</td></tr> 
     96                 * </table> 
     97                 *  
     98                 * @see com.longtailvideo.jwplayer.player.Player 
     99                 * @eventType jwplayerFullscreen 
     100                 */ 
     101                public static var JWPLAYER_FULLSCREEN:String = "jwplayerFullscreen"; 
     102 
    88103                public var id:String; 
    89104                public var client:String; 
  • trunk/fl5/src/com/longtailvideo/jwplayer/events/ViewEvent.as

    r419 r1228  
    55                 
    66                /** 
     7                 * The ViewEvent.JWPLAYER_RESIZE constant defines the value of the 
     8                 * <code>type</code> property of the event object 
     9                 * for a <code>jwplayerResize</code> event. 
     10                 * 
     11                 * @eventType jwplayerResize 
     12                 */ 
     13                public static var JWPLAYER_RESIZE:String = "jwplayerResize"; 
     14 
     15                /** 
    716                 * The ViewEvent.JWPLAYER_VIEW_PLAY constant defines the value of the 
    817                 * <code>type</code> property of the event object 
    9                  * for a <code>jwplayerReady</code> event. 
     18                 * for a <code>jwplayerViewPlay</code> event. 
    1019                 * 
    1120                 * @eventType jwplayerViewPlay 
     
    1625                 * The ViewEvent.JWPLAYER_VIEW_PAUSE constant defines the value of the 
    1726                 * <code>type</code> property of the event object 
    18                  * for a <code>jwplayerReady</code> event. 
     27                 * for a <code>jwplayerViewPause</code> event. 
    1928                 * 
    2029                 * @eventType jwplayerViewPause 
     
    2534                 * The ViewEvent.JWPLAYER_VIEW_STOP constant defines the value of the 
    2635                 * <code>type</code> property of the event object 
    27                  * for a <code>jwplayerReady</code> event. 
     36                 * for a <code>jwplayerViewStop</code> event. 
    2837                 * 
    2938                 * @eventType jwplayerViewStop 
     
    3443                 * The ViewEvent.JWPLAYER_VIEW_NEXT constant defines the value of the 
    3544                 * <code>type</code> property of the event object 
    36                  * for a <code>jwplayerReady</code> event. 
     45                 * for a <code>jwplayerViewNext</code> event. 
    3746                 * 
    3847                 * @eventType jwplayerViewNext 
     
    4352                 * The ViewEvent.JWPLAYER_VIEW_PREV constant defines the value of the 
    4453                 * <code>type</code> property of the event object 
    45                  * for a <code>jwplayerReady</code> event. 
     54                 * for a <code>jwplayerViewPrev</code> event. 
    4655                 * 
    4756                 * @eventType jwplayerViewPrev 
     
    5261                 * The ViewEvent.JWPLAYER_VIEW_MUTE constant defines the value of the 
    5362                 * <code>type</code> property of the event object 
    54                  * for a <code>jwplayerReady</code> event. 
     63                 * for a <code>jwplayerViewMute</code> event. 
    5564                 * 
    5665                 * @eventType jwplayerViewMute 
     
    6170                 * The ViewEvent.JWPLAYER_VIEW_FULLSCREEN constant defines the value of the 
    6271                 * <code>type</code> property of the event object 
    63                  * for a <code>jwplayerReady</code> event. 
     72                 * for a <code>jwplayerViewFullscreen</code> event. 
    6473                 * 
    6574                 * @eventType jwplayerViewFullscreen 
     
    7079                 * The ViewEvent.JWPLAYER_VIEW_ITEM constant defines the value of the 
    7180                 * <code>type</code> property of the event object 
    72                  * for a <code>jwplayerReady</code> event. 
     81                 * for a <code>jwplayerViewItem</code> event. 
    7382                 * 
    7483                 * @eventType jwplayerViewItem 
     
    7988                 * The ViewEvent.JWPLAYER_VIEW_VOLUME constant defines the value of the 
    8089                 * <code>type</code> property of the event object 
    81                  * for a <code>jwplayerReady</code> event. 
     90                 * for a <code>jwplayerViewVolume</code> event. 
    8291                 * 
    8392                 * @eventType jwplayerViewVolume 
     
    8897                 * The ViewEvent.JWPLAYER_VIEW_LOAD constant defines the value of the 
    8998                 * <code>type</code> property of the event object 
    90                  * for a <code>jwplayerReady</code> event. 
     99                 * for a <code>jwplayerViewLoad</code> event. 
    91100                 * 
    92101                 * @eventType jwplayerViewLoad 
     
    97106                 * The ViewEvent.JWPLAYER_VIEW_REDRAW constant defines the value of the 
    98107                 * <code>type</code> property of the event object 
    99                  * for a <code>jwplayerReady</code> event. 
     108                 * for a <code>jwplayerViewRedraw</code> event. 
    100109                 * 
    101110                 * @eventType jwplayerViewRedraw 
    102111                 */ 
    103112                public static var JWPLAYER_VIEW_REDRAW:String = "jwplayerViewRedraw"; 
    104  
     113                 
    105114                /** 
    106115                 * The ViewEvent.JWPLAYER_VIEW_SEEK constant defines the value of the 
    107116                 * <code>type</code> property of the event object 
    108                  * for a <code>jwplayerReady</code> event. 
     117                 * for a <code>jwplayerViewSeek</code> event. 
    109118                 * 
    110119                 * @eventType jwplayerViewSeek 
  • trunk/fl5/src/com/longtailvideo/jwplayer/player/JavascriptAPI.as

    r1223 r1228  
    11package com.longtailvideo.jwplayer.player { 
     2        import com.longtailvideo.jwplayer.events.GlobalEventDispatcher; 
     3        import com.longtailvideo.jwplayer.events.IGlobalEventDispatcher; 
    24        import com.longtailvideo.jwplayer.events.MediaEvent; 
    35        import com.longtailvideo.jwplayer.events.PlayerEvent; 
     
    2224                 
    2325                protected var _listeners:Object; 
    24  
     26                protected var _queuedEvents:Array = []; 
     27 
     28                 
    2529                public function JavascriptAPI(player:IPlayer) { 
    2630                        _listeners = {}; 
     
    3539                /** Delay the response to PlayerReady to allow the external interface to initialize in some browsers **/ 
    3640                protected function playerReady(evt:PlayerEvent):void { 
     41                        (_player as IGlobalEventDispatcher).addGlobalListener(queueEvents); 
     42                         
    3743                        var timer:Timer = new Timer(50, 1); 
     44                         
    3845                        timer.addEventListener(TimerEvent.TIMER_COMPLETE, function(timerEvent:TimerEvent):void { 
    3946                                var callbacks:String = _player.config.playerready ? _player.config.playerready + "," + "playerReady" : "playerReady";   
     
    4855                                                } catch (e:Error) {} 
    4956                                        } 
    50                                 } 
     57                                         
     58                                        for each (var queuedEvent:PlayerEvent in _queuedEvents) { 
     59                                                listenerCallback(queuedEvent); 
     60                                        } 
     61                                        _queuedEvents = null; 
     62                                         
     63                                } 
     64                                 
     65                                (_player as IGlobalEventDispatcher).removeGlobalListener(queueEvents); 
     66 
    5167                        }); 
    5268                        timer.start(); 
     69                } 
     70 
     71                protected function queueEvents(evt:PlayerEvent):void { 
     72                        _queuedEvents.push(evt); 
    5373                } 
    5474                 
     
    7999                                 
    80100                                // Getters 
    81                                 ExternalInterface.addCallback("jwGetBandwidth", js_getBandwidth); 
    82101                                ExternalInterface.addCallback("jwGetBuffer", js_getBuffer); 
    83102                                ExternalInterface.addCallback("jwGetDuration", js_getDuration); 
    84103                                ExternalInterface.addCallback("jwGetFullscreen", js_getFullscreen); 
    85104                                ExternalInterface.addCallback("jwGetHeight", js_getHeight); 
    86                                 ExternalInterface.addCallback("jwGetLevel", js_getLevel); 
    87                                 ExternalInterface.addCallback("jwGetLockState", js_getLockState); 
    88105                                ExternalInterface.addCallback("jwGetMute", js_getMute); 
    89106                                ExternalInterface.addCallback("jwGetPlaylist", js_getPlaylist); 
     
    105122                                ExternalInterface.addCallback("jwMute", js_mute); 
    106123                                ExternalInterface.addCallback("jwVolume", js_volume); 
    107                                  
     124 
     125                                // UNIMPLEMENTED 
     126                                //ExternalInterface.addCallback("jwGetBandwidth", js_getBandwidth);  
     127                                //ExternalInterface.addCallback("jwGetLevel", js_getLevel); 
     128                                //ExternalInterface.addCallback("jwGetLockState", js_getLockState); 
    108129                                 
    109130                        } catch(e:Error) { 
     
    145166                        else if (evt is PlayerStateEvent) 
    146167                                args = listenerCallbackState(evt as PlayerStateEvent); 
     168                        else if (evt is PlaylistEvent) 
     169                                args = listenerCallbackPlaylist(evt as PlaylistEvent); 
    147170                        else if (evt is ViewEvent && (evt as ViewEvent).data != null) 
    148                                 args['data'] = (evt as ViewEvent).data; 
     171                                args = {data: (evt as ViewEvent).data}; 
     172                        else 
     173                                args = {message: evt.message}; 
    149174                         
    150175                        var callbacks:Array = _listeners[evt.type] as Array; 
     
    177202                        if (evt.bufferPercent >= 0)             returnObj.bufferPercent = evt.bufferPercent; 
    178203                        if (evt.duration >= 0)                          returnObj.duration = evt.duration; 
    179                         if (evt.message != "")                          returnObj.message = evt.message; 
     204                        if (evt.message)                                        returnObj.message = evt.message; 
     205                        // todo: strip out 'name.properties' named properties 
    180206                        if (evt.metadata != null)                       returnObj.metadata = evt.metadata; 
    181                         if (evt.offset >= 0)                            returnObj.offset = evt.offset; 
     207                        if (evt.offset > 0)                                     returnObj.offset = evt.offset; 
    182208                        if (evt.position >= 0)                          returnObj.position = evt.position; 
    183209 
     
    193219                 
    194220                protected function listenerCallbackState(evt:PlayerStateEvent):Object { 
    195                          if (evt.type == PlayerStateEvent.JWPLAYER_PLAYER_STATE) { 
     221                        if (evt.type == PlayerStateEvent.JWPLAYER_PLAYER_STATE) { 
    196222                                return { newstate: evt.newstate, oldstate: evt.oldstate }; 
    197                          } else return {}; 
    198                 } 
    199                  
     223                        } else return {}; 
     224                } 
     225 
     226                protected function listenerCallbackPlaylist(evt:PlaylistEvent):Object { 
     227                        if (evt.type == PlaylistEvent.JWPLAYER_PLAYLIST_LOADED) { 
     228                                return { playlist: JavascriptSerialization.playlistToArray(_player.playlist) }; 
     229                        } else if (evt.type == PlaylistEvent.JWPLAYER_PLAYLIST_ITEM) { 
     230                                return { index: _player.playlist.currentIndex }; 
     231                        } else return {}; 
     232                } 
     233 
    200234                /*********************************************** 
    201235                 **                 GETTERS                   ** 
     
    211245                 
    212246                protected function js_getDuration():Number { 
    213                         return _player.playlist.currentItem.duration; 
     247                        return _player.playlist.currentItem ? _player.playlist.currentItem.duration : 0; 
    214248                } 
    215249                 
     
    223257                 
    224258                protected function js_getLevel():Number { 
    225                         return _player.playlist.currentItem.currentLevel; 
     259                        return _player.playlist.currentItem ? _player.playlist.currentItem.currentLevel : 0; 
    226260                } 
    227261                 
  • trunk/fl5/src/com/longtailvideo/jwplayer/player/Player.as

    r1207 r1228  
    11package com.longtailvideo.jwplayer.player { 
    22        import com.longtailvideo.jwplayer.controller.Controller; 
     3        import com.longtailvideo.jwplayer.events.GlobalEventDispatcher; 
     4        import com.longtailvideo.jwplayer.events.IGlobalEventDispatcher; 
    35        import com.longtailvideo.jwplayer.events.PlayerEvent; 
    46        import com.longtailvideo.jwplayer.model.IPlaylist; 
     
    3032         * @author Pablo Schklowsky 
    3133         */ 
    32         public class Player extends Sprite implements IPlayer { 
     34        public class Player extends Sprite implements IPlayer, IGlobalEventDispatcher { 
    3335                protected var model:Model; 
    3436                protected var view:View; 
    3537                protected var controller:Controller; 
     38                 
     39                protected var _dispatcher:GlobalEventDispatcher; 
    3640                 
    3741                /** Player constructor **/ 
     
    5155                        } 
    5256                        new RootReference(this); 
     57                        _dispatcher = new GlobalEventDispatcher(); 
    5358                        model = newModel(); 
    5459                        view = newView(model); 
     
    295300                } 
    296301                 
     302                 
     303                ///////////////////////////////////////////              
     304                /// IGlobalEventDispatcher implementation 
     305                ///////////////////////////////////////////              
     306                /** 
     307                 * @inheritDoc 
     308                 */ 
     309                public function addGlobalListener(listener:Function):void { 
     310                        _dispatcher.addGlobalListener(listener); 
     311                } 
     312                 
     313                 
     314                /** 
     315                 * @inheritDoc 
     316                 */ 
     317                public function removeGlobalListener(listener:Function):void { 
     318                        _dispatcher.removeGlobalListener(listener); 
     319                } 
     320                 
     321                 
     322                /** 
     323                 * @inheritDoc 
     324                 */ 
     325                public override function dispatchEvent(event:Event):Boolean { 
     326                        _dispatcher.dispatchEvent(event); 
     327                        return super.dispatchEvent(event); 
     328                } 
     329                 
    297330        } 
    298331} 
  • trunk/fl5/src/com/longtailvideo/jwplayer/player/PlayerVersion.as

    r1223 r1228  
    33         
    44        public class PlayerVersion { 
    5                 protected static var _version:String = "5.3.1223"; 
     5                protected static var _version:String = "5.3.1228"; 
    66                 
    77                public static function get version():String { 
  • trunk/fl5/src/com/longtailvideo/jwplayer/utils/JavascriptSerialization.as

    r1214 r1228  
    5151                 
    5252                public static function stripDots(obj:Object):Object { 
     53                        // Todo: create nested objects instead of removing the dots 
     54                         
    5355                        var newObj:Object = (obj is Array) ? new Array() : new Object(); 
    5456                        for (var i:String in obj) { 
  • trunk/fl5/src/com/longtailvideo/jwplayer/view/View.as

    r1149 r1228  
    272272                                dispatchEvent(new ViewEvent(ViewEvent.JWPLAYER_VIEW_FULLSCREEN, currentFSMode)); 
    273273                        } 
    274  
     274                        dispatchEvent(new ViewEvent(ViewEvent.JWPLAYER_RESIZE, {width: RootReference.stage.stageWidth, height: RootReference.stage.stageHeight})); 
     275                         
    275276                        redraw(); 
    276277                } 
Note: See TracChangeset for help on using the changeset viewer.