source: trunk/fl5/src/com/longtailvideo/jwplayer/view/PlayerLayoutManager.as @ 455

Revision 455, 3.5 KB checked in by pablo, 4 years ago (diff)

Playlist over state / fullscreen fix
PlaylistEvent.ITEM triggers play regardless of player state

Line 
1package com.longtailvideo.jwplayer.view {
2        import com.longtailvideo.jwplayer.player.Player;
3        import com.longtailvideo.jwplayer.plugins.PluginConfig;
4       
5        import flash.geom.Rectangle;
6
7
8        public class PlayerLayoutManager {
9
10                public static var LEFT:String = "left"; 
11                public static var RIGHT:String = "right"; 
12                public static var TOP:String = "top"; 
13                public static var BOTTOM:String = "bottom"; 
14                public static var NONE:String = "none"; 
15       
16                private var _player:Player;
17       
18                private var toLayout:Array;
19                private var noLayout:Array;
20               
21                private var remainingSpace:Rectangle;
22       
23                public function PlayerLayoutManager(player:Player) {
24                        _player = player;
25                }
26               
27                public function resize(width:Number, height:Number):void {
28                        toLayout = [];
29                        noLayout = [];
30                       
31                        for each (var plugin:String in _player.config.pluginNames) {
32                                addLayout(plugin);
33                        }
34                       
35                        addLayout('playlist');                 
36                        addLayout('controlbar');
37                        addLayout('display');                   
38                        addLayout('dock');                     
39                       
40                        remainingSpace = new Rectangle(0, 0, width, height);
41                        generateLayout();
42                }
43
44
45                private function addLayout(plugin:String):void {
46                        var cfg:PluginConfig = _player.config.pluginConfig(plugin);
47                        if (!_player.fullscreen && testPosition(cfg['position']) && Number(cfg['size']) > 0 ) {
48                                toLayout.push(cfg);
49                        } else {
50                                noLayout.push(cfg);
51                        }
52                }
53
54                public static function testPosition(pos:String):String {
55                        if (!pos) { return ""; }
56                       
57                        switch (pos.toLowerCase()) {
58                                case LEFT:
59                                case RIGHT:
60                                case TOP:
61                                case BOTTOM:
62                                        return pos.toLowerCase();
63                                        break;
64                                default:
65                                        return "";
66                                        break;
67                        }
68                }
69
70                protected function generateLayout():void {
71                        if (toLayout.length == 0) {
72                                for each(var item:PluginConfig in noLayout) {
73                                        if (_player.fullscreen && testPosition(item['position'])) {
74                                                item['visible'] = false;
75                                        }
76                                        assignSpace(item, remainingSpace);
77                                }
78                                _player.config.width = remainingSpace.width;
79                                _player.config.height = remainingSpace.height;
80                                return;
81                        }
82                       
83                        var config:PluginConfig = toLayout.shift() as PluginConfig;
84                        var pluginSpace:Rectangle = new Rectangle();
85                        var position:String = testPosition(config['position']);
86                        var size:Number = config['size'];
87                       
88                        switch (position) {
89                                case LEFT:
90                                        pluginSpace.x = remainingSpace.x;
91                                        pluginSpace.y = remainingSpace.y;
92                                        pluginSpace.width = size;
93                                        pluginSpace.height = remainingSpace.height;
94                                        remainingSpace.width -= size;
95                                        remainingSpace.x += size;
96                                        break;
97                                case RIGHT:
98                                        pluginSpace.x = remainingSpace.x + remainingSpace.width - size;
99                                        pluginSpace.y = remainingSpace.y;
100                                        pluginSpace.width = size;
101                                        pluginSpace.height = remainingSpace.height;
102                                        remainingSpace.width -= size;
103                                        break;
104                                case TOP:
105                                        pluginSpace.x = remainingSpace.x;
106                                        pluginSpace.y = remainingSpace.y;
107                                        pluginSpace.width = remainingSpace.width;
108                                        pluginSpace.height = size;
109                                        remainingSpace.height -= size;
110                                        remainingSpace.y += size;
111                                        break;
112                                case BOTTOM:
113                                        pluginSpace.x = remainingSpace.x;
114                                        pluginSpace.y = remainingSpace.y + remainingSpace.height - size;
115                                        pluginSpace.width = remainingSpace.width;
116                                        pluginSpace.height = size;
117                                        remainingSpace.height -= size;
118                                        break;
119                        }
120
121                        config['visible'] = true;
122                        assignSpace(config, pluginSpace);
123                       
124                        generateLayout();
125                }
126               
127                protected function assignSpace(cfg:PluginConfig, space:Rectangle):void {
128                        cfg['width']    = space.width;
129                        cfg['height']   = space.height;
130                        cfg['x']                = space.x;
131                        cfg['y']                = space.y;
132                }
133               
134               
135        }
136}
Note: See TracBrowser for help on using the repository browser.