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