source: branches/pausedseek/src/com/longtailvideo/jwplayer/model/PlayerConfig.as @ 804

Revision 804, 16.5 KB checked in by pablo, 3 years ago (diff)

This branch allows the user to seek through a paused video, with the time updating every second or so.

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