root/trunk/as2/com/jeroenwijering/players/ControlbarView.as @ 1

Revision 1, 12.7 kB (checked in by jeroen, 18 months ago)

initial commit of old repository into public one

  • Property svn:executable set to *
Line 
1/**
2* Controlbar user interface management of the players MCV pattern.
3*
4* @author       Jeroen Wijering
5* @version      1.13
6**/
7
8
9import com.jeroenwijering.players.*;
10import com.jeroenwijering.utils.*;
11import com.jeroenwijering.feeds.FeedListener;
12
13
14class com.jeroenwijering.players.ControlbarView extends AbstractView
15        implements FeedListener {
16
17
18        /** currently active item **/
19        private var currentItem:Number;
20        /** full width of the scrubbars **/
21        private var barWidths:Number;
22        /** duration of the currently playing item **/
23        private var itemLength:Number;
24        /** progress of the  currently playing item **/
25        private var itemProgress:Number = 0
26        /** do not rescale loadbar on rebuffering **/
27        private var wasLoaded:Boolean = false;
28        /** interval for hiding the display **/
29        private var hideInt:Number;
30
31
32        /** Constructor **/
33        function ControlbarView(ctr:AbstractController,cfg:Object,fed:Object) {
34                super(ctr,cfg,fed);
35                setColorsClicks();
36                setDimensions();
37                Stage.addListener(this);
38                feeder.addListener(this);
39                Mouse.addListener(this);
40        };
41
42
43        /** Sets up colors and clicks of all controlbar items. **/
44        private function setColorsClicks() {
45                var ref = this;
46                var tgt = config["clip"].controlbar;
47                tgt.col = new Color(tgt.back);
48                tgt.col.setRGB(config["backcolor"]);
49                tgt.playpause.col1 = new Color(tgt.playpause.ply);
50                tgt.playpause.col1.setRGB(config["frontcolor"]);
51                tgt.playpause.col2 = new Color(tgt.playpause.pas);
52                tgt.playpause.col2.setRGB(config["frontcolor"]);
53                tgt.playpause.pas._visible = false;
54                tgt.playpause.onRollOver = function() {
55                        this.col1.setRGB(ref.config["lightcolor"]);
56                        this.col2.setRGB(ref.config["lightcolor"]);
57                };
58                tgt.playpause.onRollOut = function() {
59                        this.col1.setRGB(ref.config["frontcolor"]);
60                        this.col2.setRGB(ref.config["frontcolor"]);
61                };
62                tgt.playpause.onRelease = function() { ref.sendEvent("playpause"); };
63                tgt.stop.col = new Color(tgt.stop.icn);
64                tgt.stop.col.setRGB(config["frontcolor"]);
65                tgt.stop.onRollOver = function() {
66                        this.col.setRGB(ref.config["lightcolor"]);
67                };
68                tgt.stop.onRollOut = function() {
69                        this.col.setRGB(ref.config["frontcolor"]);
70                };
71                tgt.stop.onRelease = function() { ref.sendEvent("stop"); };
72                tgt.prev.col = new Color(tgt.prev.icn);
73                tgt.prev.col.setRGB(config["frontcolor"]);
74                tgt.prev.onRollOver = function() {
75                        this.col.setRGB(ref.config["lightcolor"]);
76                };
77                tgt.prev.onRollOut = function() {
78                        this.col.setRGB(ref.config["frontcolor"]);
79                };
80                tgt.prev.onRelease = function() { ref.sendEvent("prev"); };
81                tgt.next.col = new Color(tgt.next.icn);
82                tgt.next.col.setRGB(config["frontcolor"]);
83                tgt.next.onRollOver = function() {
84                        this.col.setRGB(ref.config["lightcolor"]);
85                };
86                tgt.next.onRollOut = function() {
87                        this.col.setRGB(ref.config["frontcolor"]);
88                };
89                tgt.next.onRelease = function() { ref.sendEvent("next"); };
90                tgt.scrub.elpTxt.textColor = config["frontcolor"];
91                tgt.scrub.remTxt.textColor = config["frontcolor"];
92                tgt.scrub.col = new Color(tgt.scrub.icn);
93                tgt.scrub.col.setRGB(config["frontcolor"]);
94                tgt.scrub.col2 = new Color(tgt.scrub.bar);
95                tgt.scrub.col2.setRGB(config["frontcolor"]);
96                tgt.scrub.col3 = new Color(tgt.scrub.bck);
97                tgt.scrub.col3.setRGB(config["frontcolor"]);
98                tgt.scrub.bck.onRollOver = function() {
99                        this._parent.col.setRGB(ref.config["lightcolor"]);
100                };
101                tgt.scrub.bck.onRollOut = function() {
102                        this._parent.col.setRGB(ref.config["frontcolor"]);
103                };
104                tgt.scrub.bck.onPress= function() {
105                        this.onEnterFrame = function() {
106                                var xm = this._parent._xmouse;
107                                if(xm < this._parent.bck._width + this._parent.bck._x &&
108                                        xm > this._parent.bck._x) {
109                                        this._parent.icn._x = this._parent._xmouse - 1;
110                                }
111                        }
112                };
113                tgt.scrub.bck.onRelease= tgt.scrub.bck.onReleaseOutside= function() {
114                        var sec = (this._parent._xmouse-this._parent.bar._x) /
115                                ref.barWidths*ref.itemLength;
116                        ref.sendEvent("scrub",Math.round(sec));
117                        delete this.onEnterFrame;
118                };
119                tgt.scrub.bck.tabEnabled = false;
120                tgt.fs.col1 = new Color(tgt.fs.ns);
121                tgt.fs.col2 = new Color(tgt.fs.fs);
122                tgt.fs.col.setRGB(ref.config["frontcolor"]);
123                tgt.fs.col2.setRGB(ref.config["frontcolor"]);
124                tgt.fs.onRollOver = function() {
125                        this.col1.setRGB(ref.config["lightcolor"]);
126                        this.col2.setRGB(ref.config["lightcolor"]);
127                };
128                tgt.fs.onRollOut = function() {
129                        this.col1.setRGB(ref.config["frontcolor"]);
130                        this.col2.setRGB(ref.config["frontcolor"]);
131                };
132                tgt.fs.onRelease = function() {
133                        ref.sendEvent("fullscreen");
134                        this.col1.setRGB(ref.config["frontcolor"]);
135                        this.col2.setRGB(ref.config["frontcolor"]);
136                };
137                tgt.cc.col = new Color(tgt.cc.icn);
138                tgt.cc.col.setRGB(ref.config["frontcolor"]);
139                tgt.cc.onRollOver = function() {
140                        this.col.setRGB(ref.config["lightcolor"]);
141                };
142                tgt.cc.onRollOut = function() {
143                        this.col.setRGB(ref.config["frontcolor"]);
144                };
145                tgt.cc.onRelease = function() {
146                        ref.sendEvent("captions");
147                };
148                tgt.au.col = new Color(tgt.au.icn);
149                tgt.au.col.setRGB(ref.config["frontcolor"]);
150                tgt.au.onRollOver = function() {
151                        this.col.setRGB(ref.config["lightcolor"]);
152                };
153                tgt.au.onRollOut = function() {
154                        this.col.setRGB(ref.config["frontcolor"]);
155                };
156                tgt.au.onRelease = function() {
157                        ref.sendEvent("audio");
158                };
159                tgt.dl.col = new Color(tgt.dl.icn);
160                tgt.dl.col.setRGB(ref.config["frontcolor"]);
161                tgt.dl.onRollOver = function() {
162                        this.col.setRGB(ref.config["lightcolor"]);
163                };
164                tgt.dl.onRollOut = function() {
165                        this.col.setRGB(ref.config["frontcolor"]);
166                };
167                tgt.dl.onRelease = function() {
168                        ref.sendEvent("getlink",ref.currentItem);
169                };
170                tgt.vol.col = new Color(tgt.vol.bar);
171                tgt.vol.col.setRGB(config["frontcolor"]);
172                tgt.vol.col2 = new Color(tgt.vol.bck);
173                tgt.vol.col2.setRGB(config["frontcolor"]);
174                tgt.vol.col3 = new Color(tgt.vol.icn);
175                tgt.vol.col3.setRGB(config["frontcolor"]);
176                tgt.vol.onRollOver = function() {
177                        this.col.setRGB(ref.config["lightcolor"]);
178                        this.col3.setRGB(ref.config["lightcolor"]);
179                };
180                tgt.vol.onRollOut = function() {
181                        this.col.setRGB(ref.config["frontcolor"]);
182                        this.col3.setRGB(ref.config["frontcolor"]);
183                };
184                tgt.vol.onRelease = function() {
185                        this.onEnterFrame = function() {
186                                this.msk._width = this._xmouse-12;
187                        };
188                };
189                tgt.vol.onRelease = tgt.vol.onReleaseOutside = function() {
190                        ref.sendEvent("volume",(this._xmouse-12)*5);
191                        delete this.onEnterFrame;
192                };
193        };
194
195
196        /** Sets up dimensions of all controlbar items. **/
197        private function setDimensions() {
198                clearInterval(hideInt);
199                var tgt = config["clip"].controlbar;
200                var cbw  = 400;
201                // overall position and width
202                if(Stage["displayState"] == "fullScreen") {
203                        tgt._x = Math.round(Stage.width/2-200);
204                        tgt._y = Stage.height - 40;
205                        tgt._alpha = 100;
206                        tgt.back._alpha = 50;
207                        tgt.fs.fs._visible = false;
208                        tgt.fs.ns._visible = true;
209                } else if(config["displayheight"] == config["height"]-config['searchbar']) {
210                        tgt._y = config["displayheight"] - 40;
211                        if(config["displaywidth"] > 450 &&
212                                config["displaywidth"] == config["width"]) {
213                                tgt._x = Math.round(Stage.width/2-200);
214                        } else {
215                                tgt._x = 20;
216                                cbw = config["displaywidth"] - 40;
217                        }
218                        tgt.back._alpha = 40;
219                        tgt.fs.fs._visible = true;
220                        tgt.fs.ns._visible = false;
221                } else {
222                        tgt._x = 0;
223                        tgt._y = config["displayheight"];
224                        cbw = config["width"];
225                        tgt._alpha = 100;
226                        tgt.back._alpha = 100;
227                        tgt.fs.fs._visible = true;
228                        tgt.fs.ns._visible = false;
229                }
230                if(config["largecontrols"] == "true") {
231                        tgt._xscale = tgt._yscale = 200;
232                        if(Stage["displayState"] == "fullScreen") {
233                                tgt._y = Stage.height - 60;
234                                cbw = 300;
235                                tgt._x = Math.round(Stage.width/2 - 300);
236                        } else {
237                                cbw /= 2;
238                        }
239                }
240                tgt.back._width = cbw;
241                // all buttons
242                if(feeder.feed.length < 2) {
243                        tgt.prev._visible = tgt.next._visible = false;
244                        tgt.scrub.shd._width = cbw-17;
245                        tgt.scrub._x = 17;
246                } else {
247                        tgt.prev._visible = tgt.next._visible = true;
248                        tgt.scrub.shd._width = cbw-51;
249                        tgt.scrub._x = 51;
250                }
251                if(config['showstop'] == 'true') {
252                        tgt.scrub.shd._width -= 17;
253                        tgt.scrub._x += 17;
254                } else {
255                        tgt.stop._visible = false;
256                        tgt.prev._x = 17;
257                        tgt.next._x = 34;
258                }
259                var xp = cbw;
260                if(cbw > 50) {
261                        xp -= 37;
262                        tgt.scrub.shd._width -= 37;
263                        tgt.vol._x = xp;
264                } else {
265                        xp -= 1;
266                        tgt.scrub.shd._width -= 1;
267                        tgt.vol._x = xp;
268                }
269                if (feeder.audio == true) {
270                        xp -= 17;
271                        tgt.scrub.shd._width -= 17;
272                        tgt.au._x = xp;
273                        tgt.au._visible = true;
274                } else {
275                        tgt.au._visible = false;
276                }
277                if (feeder.captions == true) {
278                        xp -= 17;
279                        tgt.scrub.shd._width -= 17;
280                        tgt.cc._x = xp;
281                        tgt.cc._visible = true;
282                } else {
283                        tgt.cc._visible = false;
284                }
285                if (config["showdownload"] == "true") {
286                        xp -= 17;
287                        tgt.scrub.shd._width -= 17;
288                        tgt.dl._x = xp;
289                } else {
290                        tgt.dl._visible = false;
291                }
292                if((Stage["displayState"] == undefined ||
293                        config["usefullscreen"] == "false" ||
294                        feeder.onlymp3s == true) &&
295                        config["fsbuttonlink"] == undefined) {
296                        tgt.fs._visible = false;
297                } else {
298                        xp -= 18;
299                        tgt.scrub.shd._width -= 18;
300                        tgt.fs._x = xp;
301                }
302                if(config["showdigits"] == "false" || tgt.scrub.shd._width < 120 ||
303                        System.capabilities.version.indexOf("7,0,") > -1) {
304                        tgt.scrub.elpTxt._visible = tgt.scrub.remTxt._visible = false;
305                        tgt.scrub.bar._x = tgt.scrub.bck._x = tgt.scrub.icn._x = 5;
306                        barWidths = tgt.scrub.bck._width = tgt.scrub.shd._width - 10;
307                } else {       
308                        tgt.scrub.elpTxt._visible = tgt.scrub.remTxt._visible = true;
309                        tgt.scrub.bar._x = tgt.scrub.bck._x = tgt.scrub.icn._x = 42;
310                        barWidths = tgt.scrub.bck._width = tgt.scrub.shd._width - 84;
311                        tgt.scrub.remTxt._x = tgt.scrub.shd._width - 39;
312                }       
313                tgt.scrub.bar._width = 0;
314        };
315
316
317        /** Show and hide the play/pause button and show activity icon **/
318        private function setState(stt:Number) {
319                var tgt = config["clip"].controlbar.playpause;
320                switch(stt) {
321                        case 0:
322                                tgt.ply._visible = true;
323                                tgt.pas._visible = false;
324                                break;
325                        case 1:
326                                tgt.pas._visible = true;
327                                tgt.ply._visible = false;
328                                break;
329                        case 2:
330                                tgt.pas._visible = true;
331                                tgt.ply._visible = false;
332                                break;
333                }
334        };
335
336
337        /** Print current time to controlBar **/
338        private function setTime(elp:Number,rem:Number) {
339                itemLength = elp + rem;
340                itemProgress = Math.round(rem/(itemLength)*100);
341                var tgt = config["clip"].controlbar.scrub;
342                var w = Math.floor(elp/(elp+rem)*barWidths) - 2;
343                if(rem > 0) {
344                        tgt.icn._visible = true;
345                        tgt.bar._visible = true;
346                        elp == 0 || w < 2 ? tgt.bar._width = 0: tgt.bar._width = w - 2;
347                        tgt.icn._x = tgt.bar._width + tgt.bar._x + 1;
348                } else {
349                        tgt.icn._visible = false;
350                        tgt.bar._visible = false;
351                }
352                tgt.elpTxt.text = StringMagic.addLeading(elp/60) + ":" +
353                        StringMagic.addLeading(elp%60);
354                if(tgt.bck._width == barWidths) {
355                        if(config['showdigits'] == "total") {
356                                tgt.remTxt.text = StringMagic.addLeading((elp+rem)/60)+ ":" +
357                                        StringMagic.addLeading((elp+rem)%60);
358                        } else {
359                                tgt.remTxt.text = StringMagic.addLeading(rem/60)+ ":" +
360                                        StringMagic.addLeading(rem%60);
361                        }
362                }
363        };
364
365
366        /** New item is loaded **/
367        private function setItem(prm:Number) {
368                wasLoaded = false;
369                currentItem = prm;
370                config["clip"].controlbar.scrub.icn._alpha = 100;
371        };
372
373
374        /** Print current buffer amount to controlbar **/
375        private function setLoad(pct:Number) {
376                var tgt = config["clip"].controlbar.scrub;
377                if(wasLoaded == false) {
378                        tgt.bck._width = Math.round(barWidths*pct/100);
379                }
380                tgt.remTxt.text = Math.round(pct)+" %";
381                pct == 100 ? wasLoaded = true: null;
382        };
383
384
385        /** Reflect current volume in volumebar **/
386        private function setVolume(pr1:Number) {
387                var tgt = config["clip"].controlbar.vol;
388                tgt.msk._width = Math.round(pr1/5);
389                if(pr1 == 0) {
390                        tgt.icn._alpha = 40;
391                } else {
392                        tgt.icn._alpha = 100;
393                }
394        };
395
396
397        /** Catches stage resizing **/
398        public function onResize() {
399                if(config['displayheight'] > config["height"]+10) {
400                        config["height"] = config["displayheight"] = Stage.height;
401                        config["width"] = Stage.width;
402                        if(config['displaywidth'] == config["width"]) {
403                                config["displaywidth"] = Stage.width;
404                        }
405                }
406                setDimensions();
407        };
408
409
410        /** Catches fullscreen escape  **/
411        public function onFullScreen(fs:Boolean) {
412                if(fs == false) {
413                        setDimensions();
414                        Animations.fadeIn(config['clip'].controlbar);
415                } else {
416                        hideInt = setInterval(this,"hideBar",1000);
417                }
418        };
419
420
421        /** after a delay, the controlbar is hidden **/
422        private function hideBar() {
423                Animations.fadeOut(config['clip'].controlbar);
424                Mouse.hide();
425                clearInterval(hideInt);
426        }
427
428
429        /** Mouse move shows controlbar **/
430        public function onMouseMove() {
431                Mouse.show();
432                if(config["displayheight"] == config["height"]-config['searchbar'] ||
433                        Stage["displayState"] == "fullScreen") {
434                        Animations.fadeIn(config['clip'].controlbar);
435                        clearInterval(hideInt);
436                        if(!config["clip"].controlbar.hitTest(_root._xmouse,_root._ymouse)) {
437                                hideInt = setInterval(this,"hideBar",500);
438                        }
439                }
440        };
441
442
443        public function onFeedUpdate(typ:String) {
444                setDimensions();
445        };
446
447
448}
Note: See TracBrowser for help on using the browser.