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

Revision 2049, 18.1 KB checked in by pablo, 16 months ago (diff)

Implements InStream API (644), by merging instream branch

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