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

Revision 467, 16.0 KB checked in by pablo, 4 years ago (diff)

Cookied params: PlayerConfig.setCookie()

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