source: trunk/fl5/src/com/longtailvideo/jwplayer/model/PlayerConfig.as @ 475

Revision 475, 16.3 KB checked in by pablo, 4 years ago (diff)

Playlist loading consistency fixes

Line 
1package com.longtailvideo.jwplayer.model {
2        import com.longtailvideo.jwplayer.plugins.PluginConfig;
3        import com.longtailvideo.jwplayer.utils.Configger;
4        import com.longtailvideo.jwplayer.utils.Strings;
5        import com.longtailvideo.jwplayer.utils.TypeChecker;
6       
7        import flash.events.EventDispatcher;
8
9        /**
10         * Configuration data for the player
11         *
12         * @author Pablo Schklowsky
13         */
14        public dynamic class PlayerConfig extends EventDispatcher {
15                /** Internal playlist reference **/
16//              private var _list:Playlist;
17                private var _singleItem:PlaylistItem;
18
19                private var _playlistfile:String        = null;
20
21                private var _autostart:Boolean          = false;
22                private var _bufferlength:Number        = 5;
23                private var _displayclick:String        = "play";
24                private var _displaytitle:Boolean       = true;
25                private var _fullscreen:Boolean         = false;
26                private var _item:Number                        = 0;
27                private var _linktarget:String          = "_blank";
28                private var _mute:Boolean                       = false;
29                private var _repeat:String                      = "none";
30                private var _shuffle:Boolean            = false;
31                private var _smoothing:Boolean          = true;
32                private var _stretching:String          = "uniform";
33                private var _volume:Number                      = 90;
34
35                private var _backcolor:uint                     = 0x000000;
36                private var _frontcolor:uint            = 0x000000;
37                private var _lightcolor:uint            = 0x000000;
38                private var _screencolor:uint           = 0x000000;
39               
40                private var _controlbar:String          = "bottom";
41                private var _dock:Boolean                       = false;
42                private var _height:Number                      = 400;
43                private var _icons:Boolean                      = true;
44                private var _logo:String                        = null;
45                private var _playlist:String            = "none";
46                private var _playlistsize:Number        = 180;
47                private var _skin:String                        = null;
48                private var _width:Number                       = 280;
49               
50                private var _plugins:String             = null
51                private var _pluginConfig:Object        = {};
52               
53                private var _playerready:String         = "";
54               
55                public function PlayerConfig():void {
56                        controlbar = _controlbar;
57                        playlist = _playlist;
58                        playlistsize = _playlistsize;
59//                      _list = newlist;
60//                      setPlaylist(newlist);
61                       
62                        //Unsupported config variables
63                        this['aboutlink'] = "http://www.longtailvideo.com/players/jw-flv-player/";
64                }
65               
66/*             
67                public function setPlaylist(list:Playlist):void {
68                        _list = list;
69                }
70*/             
71                public function setConfig(config:Object):void {
72                        var playlistItems:Boolean = false;
73                        if (!_singleItem) { _singleItem = new PlaylistItem(); }
74                        for (var item:String in config) {
75                                if (_singleItem.hasOwnProperty(item)) {
76                                        if (item == "file" && Strings.extension(config[item]) == "xml") {
77                                                setProperty("playlistfile", config[item]);                                     
78//                                      } //else if (_list.length > 0) {
79//                                              _list.currentItem[item] = config[item];
80                                        } else {
81                                                _singleItem[item] = config[item];
82                                                playlistItems = true;
83                                        }
84                                } else if (item.indexOf(".") > 0) {
85                                        setPluginProperty(item, config[item]);
86                                } else if (config[item] != null) {
87                                        setProperty(item, config[item]);
88                                }
89                        }
90//                      if (playlistItems && _list.length == 0) {
91//                              _list.insertItem(newItem, 0);
92//                      }
93                }
94               
95                private function setProperty(name:String, value:String):void {
96                        if (hasOwnProperty(name)) {
97                                try {
98                                        this[name] = TypeChecker.fromString(value, TypeChecker.getType(this, name));
99                                } catch (e:Error) {
100                                        // 'name' was a read-only property
101                                }
102                        } else {
103                                this[name] = value;
104                        }
105                }
106
107                /**
108                 * Sets the value of a plugin config property
109                 * @param name The parameter name in the form "pluginname.propertyname"
110                 * @param value The value to set.
111                 */
112                private function setPluginProperty(name:String, value:String):void {
113                        var pluginName:String = name.substring(0, name.indexOf(".")).toLowerCase();
114                        var pluginProperty:String = name.substring(name.indexOf(".") + 1, name.length).toLowerCase();
115
116                        if (pluginName && pluginProperty && value) {
117                                if (!_pluginConfig.hasOwnProperty(pluginName)) {
118                                        _pluginConfig[pluginName] = new PluginConfig(pluginName);
119                                }
120                                _pluginConfig[pluginName][pluginProperty] = TypeChecker.fromString(value);
121                        }
122                }
123
124                /**
125                 * Returns a string representation of the playlist's current PlaylistItem property.
126                 * @param key The requested PlaylistItem property
127                 */
128                private function playlistItem(key:String):String {
129                        try {
130//                              return _list.currentItem[key].toString();
131                                return _singleItem[key].toString();
132                        } catch (e:Error) {
133                        }
134
135                        return "";
136                }
137
138                /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
139                // PLAYLIST PROPERTIES
140                /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
141               
142                /** Location of xml playlist file to load **/
143                public function get playlistfile():String { return _playlistfile; }
144                public function set playlistfile(x:String):void { _playlistfile = x; }
145
146
147                /** Author of the video, shown in the display or playlist. **/
148                public function get author():String { return playlistItem('author'); }
149
150                /** Publish date of the media file. **/
151                public function get date():String { return playlistItem('date'); }
152
153                /** Text description of the file. **/
154                public function get description():String { return playlistItem('description'); }
155
156                /** Duration of the file in seconds. **/
157                public function get duration():String { return playlistItem('duration'); }
158
159                /** Location of the mediafile or playlist to play. **/
160                public function get file():String { return playlistItem('file'); }
161
162                /** Location of a preview image; shown in display and playlist. **/
163                public function get image():String { return playlistItem('image'); }
164               
165                /** URL to an external page the display, controlbar and playlist can link to. **/
166                public function get link():String { return playlistItem('link'); }
167
168                /** Unique identifier. **/             
169                public function get mediaid():String {                  return playlistItem('mediaid');         }               
170               
171                /** Position in seconds where playback has to start. Won't work for regular (progressive) videos, but only for streaming (HTTP / RTMP). **/
172                public function get start():String { return playlistItem('start'); }
173               
174                /** Location of an rtmp/http server instance to use for streaming. Can be an RTMP application or external PHP/ASP file. **/
175                public function get streamer():String { return playlistItem('streamer'); }
176               
177                /** Keywords associated with the media file. **/
178                public function get tags():String { return playlistItem('tags'); }
179
180                /** Title of the video, shown in the display or playlist. **/
181                public function get title():String { return playlistItem('title'); }
182
183                /**
184                 * By default, the type is detected by the player based upon the file extension. If there's no suitable
185                 * extension or the player detects the type wrong, it can be manually set. The following default types are
186                 * supported:
187                 * <ul>
188                 * <li>video: progressively downloaded FLV / MP4 video, but also AAC audio.</li>
189                 * <li>sound: progressively downloaded MP3 files.</li>
190                 * <li>image: JPG/GIF/PNG images.</li>
191                 * <li>youtube: videos from Youtube.</li>
192                 * <li>http: FLV/MP4 videos played as http speudo-streaming.</li>
193                 * <li>rtmp: FLV/MP4/MP3 files played from an RTMP server.</li>
194                 * </ul>
195                 **/
196                public function get provider():String { return playlistItem('provider'); }
197
198                /** Deprecated.  Use "provider" flashvar. **/
199                public function get type():String { return playlistItem('provider'); }
200
201                /** PlaylistItem representing single-item playlist based on flashvars (e.g. config[file], config[image], etc. **/
202                public function get singleItem():PlaylistItem { return _singleItem; }
203
204                /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
205                // LAYOUT PROPERTIES
206                /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
207
208                /** Background color of the controlbar and playlist. This is white with the default skin. **/
209                public function get backcolor():uint { return _backcolor; }
210                public function set backcolor(x:uint):void { _backcolor = x; }
211               
212                /** Color of all icons and texts in the controlbar and playlist. **/
213                public function get frontcolor():uint { return _frontcolor; }
214                public function set frontcolor(x:uint):void { _frontcolor = x; }
215
216                /** Color of an icon or text when you rollover it with the mouse. **/
217                public function get lightcolor():uint { return _lightcolor; }
218                public function set lightcolor(x:uint):void { _lightcolor = x; }
219
220                /** Background color of the display. **/
221                public function get screencolor():uint { return _screencolor; }
222                public function set screencolor(x:uint):void { _screencolor= x; }
223
224                /** Position of the controlbar. Can be set to top, bottom, over and none.  @default bottom **/
225                public function get controlbar():String {
226                        if (pluginConfig('controlbar').hasOwnProperty('position'))
227                                return pluginConfig('controlbar')['position'];
228                        else return _controlbar;
229                }
230                public function set controlbar(x:String):void {
231                        setPluginProperty('controlbar.position', x.toLowerCase());
232                }
233
234                /** Set this to true to show the dock with large buttons in the top right of the player. Available since 4.5.  @default true **/
235                public function get dock():Boolean { return _dock; }
236                public function set dock(x:Boolean):void { _dock = x; }
237
238                /** Height of the display in pixels. @default 280 **/
239                public function get height():Number { return _height; }
240                public function set height(x:Number):void { _height = x; }
241
242                /** Set this to false to hide the play button and buffering icon in the middle of the video. Available since 4.2.  @default true **/
243                public function get icons():Boolean { return _icons; }
244                public function set icons(x:Boolean):void { _icons = x; }
245
246                /** Location of an external jpg, png or gif image to show in a corner of the display. With the default skin, this is top-right, but every skin can freely place the logo. **/
247                public function get logo():String { return _logo; }
248                public function set logo(x:String):void { _logo = x; }
249
250                /** Position of the playlist. Can be set to bottom, over, right or none. @default none **/
251                public function get playlist():String {
252                        if (pluginConfig('playlist').hasOwnProperty('position'))
253                                return pluginConfig('playlist')['position'];
254                        else return _playlist;
255                }
256                public function set playlist(x:String):void {
257                        setPluginProperty('playlist.position', x.toLowerCase());
258                }
259
260                /** When below this refers to the height, when right this refers to the width of the playlist. @default 180 **/
261                public function get playlistsize():Number { return _playlistsize; }
262                public function set playlistsize(x:Number):void {
263                        _playlistsize = x;
264                        setPluginProperty('playlist.size', x.toString());
265                }
266
267                /**
268                 * Location of a SWF or ZIP file with the player graphics. The player skinning documentation gives more info on this. 
269                 * SVN contains a couple of example skins.
270                 **/
271                public function get skin():String { return _skin; }
272                public function set skin(x:String):void { _skin = x; }
273
274                /** Width of the display in pixels. @default 400 **/
275                public function get width():Number { return _width; }
276                public function set width(x:Number):void { _width = x; }
277
278                /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
279                // BEHAVIOR PROPERTIES
280                /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
281
282                /** Automatically start the player on load. @default false **/
283                public function get autostart():Boolean { return _autostart; }
284                public function set autostart(x:Boolean):void { _autostart = x; }
285
286                /**
287                 * Number of seconds of the file that has to be loaded before starting. Set this to a low value to enable instant-start and to a
288                 * high value to get less mid-stream buffering.
289                 * @default 1
290                 **/
291                public function get bufferlength():Number { return _bufferlength; }
292                public function set bufferlength(x:Number):void { _bufferlength = x; }
293
294                /**
295                 * What to do when one clicks the display. Can be play, link, fullscreen, none, mute, next. When set to none, the handcursor is
296                 * also not shown. @default play
297                 **/
298                public function get displayclick():String { return _displayclick; }
299                public function set displayclick(x:String):void { _displayclick = x; }
300
301                /** Set this to true to print the title of a video in the display. @default true **/
302                public function get displaytitle():Boolean { return _displaytitle; }
303                public function set displaytitle(x:Boolean):void { _displaytitle = x; }
304
305                /** Current fullscreen state **/               
306                public function get fullscreen():Boolean { return _fullscreen; }
307                private function set fullscreen(x:Boolean):void { _fullscreen = x; }           
308               
309                /** PlaylistItem that should start to play. Use this to set a specific start-item. @default 0 **/
310                public function get item():Number { return _item; }
311                public function set item(x:Number):void { _item = x; }
312
313                /** Browserframe where link from the display are opened in. Some possibilities are '_self' (same frame) or '_blank' (new browserwindow). @default _blank **/
314                public function get linktarget():String { return _linktarget; }
315                public function set linktarget(x:String):void { _linktarget = x; }
316               
317                /** Mute all sounds on startup. This value is set in a user cookie, and is retrieved the next time the player loads. **/
318                public function get mute():Boolean { return _mute; }
319                private function set mute(x:Boolean):void { _mute = x; }
320
321                /** Set to list to play the entire playlist once, to always to continously play the song/video/playlist and to single to continue repeating the selected file in a playlist. @default none **/
322                public function get repeat():String { return _repeat; }
323                public function set repeat(x:String):void { _repeat = x; }
324
325                /** Shuffle playback of playlist items. @default false **/
326                public function get shuffle():Boolean { return _shuffle; }
327                public function set shuffle(x:Boolean):void { _shuffle = x; }
328
329                /** this sets the smoothing of videos, so you won't see blocks when a video is upscaled. Set this to false to get performance improvements with old computers / big files. Available since 4.4. @default false **/
330                public function get smoothing():Boolean { return _smoothing; }
331                public function set smoothing(x:Boolean):void { _smoothing = x; }
332
333                /** Defines how to resize images in the display. Can be none (no stretching), exactfit (disproportionate), uniform (stretch with black borders) or fill (uniform, but completely fill the display). @default uniform **/
334                public function get stretching():String{ return _stretching; }
335                public function set stretching(x:String):void { _stretching = x; }
336
337                /** Startup volume of the player. Can be 0 to 100. Is saved in a cookie. @default 90 **/
338                public function get volume():Number { return _volume; }
339                public function set volume(x:Number):void { _volume = x; }
340
341                /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
342                // PLUGINS
343                /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
344
345                /** Which plugins to load **/           
346                public function get plugins():String { return _plugins; }
347                public function set plugins(x:String):void { _plugins = x; }
348
349                /** Javascript player ready callback handlers **/               
350                public function get playerready():String { return _playerready; }
351                public function set playerready(x:String):void { _playerready = x; }
352               
353                /**
354                 * Returns a PluginConfig containing plugin configuration information
355                 *
356                 * @param pluginName Name of the plugin whose config to return.
357                 */
358                public function pluginConfig(pluginName:String):PluginConfig {
359                        if (_pluginConfig.hasOwnProperty(pluginName)) {
360                                return _pluginConfig[pluginName] as PluginConfig;
361                        } else {
362                                var newConfig:PluginConfig = new PluginConfig(pluginName);
363                                _pluginConfig[pluginName] = newConfig;
364                                return newConfig;
365                        }
366                }
367               
368                /**
369                 * A list of available pluginConfig keys.
370                 */
371                public function get pluginNames():Array {
372                        var names:Array = [];
373                        for (var plug:String in _pluginConfig) {
374                                if ( (['controlbar','playlist','dock','display']).indexOf(plug) == -1 ) {
375                                        names.push(plug);
376                                }
377                        }
378                        return names;
379                }
380               
381                public function setCookie(name:String, value:*):void {
382                        Configger.saveCookie(name, value);                     
383                }
384
385        }
386}
Note: See TracBrowser for help on using the repository browser.