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

Revision 1280, 17.0 KB checked in by jeroen, 4 years ago (diff)

fixed a bug in RTMPT error handling. Fixed a bug in HTTP continuous bitrate switching. Fixed a bug for playlist PNG rollovers without itemActive element. Added logic for hiding the image/description of playlist buttons when the button is <40px high or <240px wide. Added RST documentation on HTTP _droppedframes, HTTP DVR, RTMP DVRCast, RTMP _droppedframes, RTMP Tunneling and small playlist button element hiding.

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