| 1 | package com.longtailvideo.jwplayer.model { |
|---|
| 2 | import com.longtailvideo.jwplayer.plugins.PluginConfig; |
|---|
| 3 | import com.longtailvideo.jwplayer.utils.TypeChecker; |
|---|
| 4 | |
|---|
| 5 | import flash.events.EventDispatcher; |
|---|
| 6 | import flash.utils.getQualifiedClassName; |
|---|
| 7 | |
|---|
| 8 | /** |
|---|
| 9 | * Configuration data for the player |
|---|
| 10 | * |
|---|
| 11 | * @author Pablo Schklowsky |
|---|
| 12 | */ |
|---|
| 13 | public dynamic class PlayerConfig extends EventDispatcher { |
|---|
| 14 | /** Internal playlist reference **/ |
|---|
| 15 | private var _list:Playlist; |
|---|
| 16 | |
|---|
| 17 | private var _autostart:Boolean = false; |
|---|
| 18 | private var _bufferlength:Number = 1; |
|---|
| 19 | private var _displayclick:String = "play"; |
|---|
| 20 | private var _displaytitle:Boolean = true; |
|---|
| 21 | private var _item:Number = 0; |
|---|
| 22 | private var _linktarget:String = "_blank"; |
|---|
| 23 | private var _mute:Boolean = false; |
|---|
| 24 | private var _repeat:String = "none"; |
|---|
| 25 | private var _shuffle:Boolean = false; |
|---|
| 26 | private var _smoothing:Boolean = false; |
|---|
| 27 | private var _stretching:String = "uniform"; |
|---|
| 28 | private var _volume:Number = 90; |
|---|
| 29 | |
|---|
| 30 | private var _backcolor:uint; |
|---|
| 31 | private var _frontcolor:uint; |
|---|
| 32 | private var _lightcolor:uint; |
|---|
| 33 | private var _screencolor:uint; |
|---|
| 34 | private var _controlbar:String = "none"; |
|---|
| 35 | private var _dock:Boolean = false; |
|---|
| 36 | private var _height:Number = 400; |
|---|
| 37 | private var _icons:Boolean = true; |
|---|
| 38 | private var _logo:String; |
|---|
| 39 | private var _playlist:String = "none"; |
|---|
| 40 | private var _playlistsize:Number = 180; |
|---|
| 41 | private var _skin:String; |
|---|
| 42 | private var _width:Number = 280; |
|---|
| 43 | |
|---|
| 44 | private var _pluginConfig:Object = {}; |
|---|
| 45 | |
|---|
| 46 | public function PlayerConfig(playlist:Playlist):void { |
|---|
| 47 | setPlaylist(playlist); |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | public function setPlaylist(list:Playlist):void { |
|---|
| 51 | _list = list; |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | public function setConfig(config:Object):void { |
|---|
| 55 | if (getQualifiedClassName(config) != "Object") |
|---|
| 56 | return; |
|---|
| 57 | |
|---|
| 58 | var newItem:PlaylistItem = new PlaylistItem(); |
|---|
| 59 | var playlistItems:Boolean = false; |
|---|
| 60 | for (var item:String in config) { |
|---|
| 61 | if (newItem.hasOwnProperty(item)) { |
|---|
| 62 | newItem[item] = config[item]; |
|---|
| 63 | playlistItems = true; |
|---|
| 64 | } else if (item.indexOf(".") > 0) { |
|---|
| 65 | setPluginProperty(item, config[item]); |
|---|
| 66 | } else { |
|---|
| 67 | setProperty(item, config[item]); |
|---|
| 68 | } |
|---|
| 69 | } |
|---|
| 70 | if (playlistItems) { |
|---|
| 71 | _list.insertItem(newItem, 0); |
|---|
| 72 | } |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | private function setProperty(name:String, value:String):void { |
|---|
| 76 | if (hasOwnProperty(name)) { |
|---|
| 77 | try { |
|---|
| 78 | this[name] = TypeChecker.fromString(value, TypeChecker.getType(this, name)); |
|---|
| 79 | } catch (e:Error) { |
|---|
| 80 | // 'name' was a read-only property |
|---|
| 81 | } |
|---|
| 82 | } else { |
|---|
| 83 | this[name] = value; |
|---|
| 84 | } |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | /** |
|---|
| 88 | * Sets the value of a plugin config property |
|---|
| 89 | * @param name The parameter name in the form "pluginname.propertyname" |
|---|
| 90 | * @param value The value to set. |
|---|
| 91 | */ |
|---|
| 92 | private function setPluginProperty(name:String, value:String):void { |
|---|
| 93 | var pluginName:String = name.substring(0, name.indexOf(".")-1).toLowerCase(); |
|---|
| 94 | var pluginProperty:String = name.substring(name.indexOf(".")+1, name.length-1).toLowerCase(); |
|---|
| 95 | |
|---|
| 96 | if(pluginName && pluginProperty && value) { |
|---|
| 97 | if (!_pluginConfig.hasOwnProperty(pluginName)) { |
|---|
| 98 | _pluginConfig[pluginName] = new PluginConfig(pluginName); |
|---|
| 99 | } |
|---|
| 100 | _pluginConfig[pluginName][pluginProperty] = TypeChecker.fromString(value); |
|---|
| 101 | } |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | /** |
|---|
| 105 | * Returns a string representation of the playlist's current PlaylistItem property. |
|---|
| 106 | * @param key The requested PlaylistItem property |
|---|
| 107 | */ |
|---|
| 108 | private function playlistItem(key:String):String { |
|---|
| 109 | try { |
|---|
| 110 | return _list.currentItem[key].toString(); |
|---|
| 111 | } catch (e:Error) { |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | return ""; |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|---|
| 118 | // PLAYLIST PROPERTIES |
|---|
| 119 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|---|
| 120 | |
|---|
| 121 | /** Author of the video, shown in the display or playlist. **/ |
|---|
| 122 | public function get author():String { return playlistItem('author'); } |
|---|
| 123 | |
|---|
| 124 | /** Publish date of the media file. **/ |
|---|
| 125 | public function get date():String { return playlistItem('date'); } |
|---|
| 126 | |
|---|
| 127 | /** Text description of the file. **/ |
|---|
| 128 | public function get description():String { return playlistItem('description'); } |
|---|
| 129 | |
|---|
| 130 | /** Duration of the file in seconds. **/ |
|---|
| 131 | public function get duration():String { return playlistItem('duration'); } |
|---|
| 132 | |
|---|
| 133 | /** Location of the mediafile or playlist to play. **/ |
|---|
| 134 | public function get file():String { return playlistItem('file'); } |
|---|
| 135 | |
|---|
| 136 | /** Location of a preview image; shown in display and playlist. **/ |
|---|
| 137 | public function get image():String { return playlistItem('image'); } |
|---|
| 138 | |
|---|
| 139 | /** URL to an external page the display, controlbar and playlist can link to. **/ |
|---|
| 140 | public function get link():String { return playlistItem('link'); } |
|---|
| 141 | |
|---|
| 142 | /** Position in seconds where playback has to start. Won't work for regular (progressive) videos, but only for streaming (HTTP / RTMP). **/ |
|---|
| 143 | public function get start():String { return playlistItem('start'); } |
|---|
| 144 | |
|---|
| 145 | /** Location of an rtmp/http server instance to use for streaming. Can be an RTMP application or external PHP/ASP file. **/ |
|---|
| 146 | public function get streamer():String { return playlistItem('streamer'); } |
|---|
| 147 | |
|---|
| 148 | /** Keywords associated with the media file. **/ |
|---|
| 149 | public function get tags():String { return playlistItem('tags'); } |
|---|
| 150 | |
|---|
| 151 | /** Title of the video, shown in the display or playlist. **/ |
|---|
| 152 | public function get title():String { return playlistItem('title'); } |
|---|
| 153 | |
|---|
| 154 | /** |
|---|
| 155 | * By default, the type is detected by the player based upon the file extension. If there's no suitable |
|---|
| 156 | * extension or the player detects the type wrong, it can be manually set. The following default types are |
|---|
| 157 | * supported: |
|---|
| 158 | * <ul> |
|---|
| 159 | * <li>video: progressively downloaded FLV / MP4 video, but also AAC audio.</li> |
|---|
| 160 | * <li>sound: progressively downloaded MP3 files.</li> |
|---|
| 161 | * <li>image: JPG/GIF/PNG images.</li> |
|---|
| 162 | * <li>youtube: videos from Youtube.</li> |
|---|
| 163 | * <li>http: FLV/MP4 videos played as http speudo-streaming.</li> |
|---|
| 164 | * <li>rtmp: FLV/MP4/MP3 files played from an RTMP server.</li> |
|---|
| 165 | * </ul> |
|---|
| 166 | **/ |
|---|
| 167 | public function get type():String { return playlistItem('type'); } |
|---|
| 168 | |
|---|
| 169 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|---|
| 170 | // LAYOUT PROPERTIES |
|---|
| 171 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|---|
| 172 | |
|---|
| 173 | /** Background color of the controlbar and playlist. This is white with the default skin. **/ |
|---|
| 174 | public function get backcolor():uint { return _backcolor; } |
|---|
| 175 | public function set backcolor(x:uint):void { _backcolor = x; } |
|---|
| 176 | |
|---|
| 177 | /** Color of all icons and texts in the controlbar and playlist. **/ |
|---|
| 178 | public function get frontcolor():uint { return _frontcolor; } |
|---|
| 179 | public function set frontcolor(x:uint):void { _frontcolor = x; } |
|---|
| 180 | |
|---|
| 181 | /** Color of an icon or text when you rollover it with the mouse. **/ |
|---|
| 182 | public function get lightcolor():uint { return _lightcolor; } |
|---|
| 183 | public function set lightcolor(x:uint):void { _lightcolor = x; } |
|---|
| 184 | |
|---|
| 185 | /** Background color of the display. **/ |
|---|
| 186 | public function get screencolor():uint { return _screencolor; } |
|---|
| 187 | public function set screencolor(x:uint):void { _screencolor= x; } |
|---|
| 188 | |
|---|
| 189 | /** Position of the controlbar. Can be set to top, bottom, over and none. @default bottom **/ |
|---|
| 190 | public function get controlbar():String { return _controlbar; } |
|---|
| 191 | public function set controlbar(x:String):void { _controlbar= x; } |
|---|
| 192 | |
|---|
| 193 | /** Set this to true to show the dock with large buttons in the top right of the player. Available since 4.5. @default true **/ |
|---|
| 194 | public function get dock():Boolean { return _dock; } |
|---|
| 195 | public function set dock(x:Boolean):void { _dock = x; } |
|---|
| 196 | |
|---|
| 197 | /** Height of the display in pixels. @default 280 **/ |
|---|
| 198 | public function get height():Number { return _height; } |
|---|
| 199 | public function set height(x:Number):void { _height = x; } |
|---|
| 200 | |
|---|
| 201 | /** Set this to false to hide the play button and buffering icon in the middle of the video. Available since 4.2. @default true **/ |
|---|
| 202 | public function get icons():Boolean { return _icons; } |
|---|
| 203 | public function set icons(x:Boolean):void { _icons = x; } |
|---|
| 204 | |
|---|
| 205 | /** 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. **/ |
|---|
| 206 | public function get logo():String { return _logo; } |
|---|
| 207 | public function set logo(x:String):void { _logo = x; } |
|---|
| 208 | |
|---|
| 209 | /** Position of the playlist. Can be set to bottom, over, right or none. @default none **/ |
|---|
| 210 | public function get playlist():String { return _playlist; } |
|---|
| 211 | public function set playlist(x:String):void { _playlist = x; } |
|---|
| 212 | |
|---|
| 213 | /** When below this refers to the height, when right this refers to the width of the playlist. @default 180 **/ |
|---|
| 214 | public function get playlistsize():Number { return _playlistsize; } |
|---|
| 215 | public function set playlistsize(x:Number):void { _playlistsize = x; } |
|---|
| 216 | |
|---|
| 217 | /** |
|---|
| 218 | * Location of a SWF or ZIP file with the player graphics. The player skinning documentation gives more info on this. |
|---|
| 219 | * SVN contains a couple of example skins. |
|---|
| 220 | **/ |
|---|
| 221 | public function get skin():String { return _skin; } |
|---|
| 222 | public function set skin(x:String):void { _skin = x; } |
|---|
| 223 | |
|---|
| 224 | /** Width of the display in pixels. @default 400 **/ |
|---|
| 225 | public function get width():Number { return _width; } |
|---|
| 226 | public function set width(x:Number):void { _width = x; } |
|---|
| 227 | |
|---|
| 228 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|---|
| 229 | // BEHAVIOR PROPERTIES |
|---|
| 230 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|---|
| 231 | |
|---|
| 232 | /** Automatically start the player on load. @default false **/ |
|---|
| 233 | public function get autostart():Boolean { return _autostart; } |
|---|
| 234 | public function set autostart(x:Boolean):void { _autostart = x; } |
|---|
| 235 | |
|---|
| 236 | /** |
|---|
| 237 | * 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 |
|---|
| 238 | * high value to get less mid-stream buffering. |
|---|
| 239 | * @default 1 |
|---|
| 240 | **/ |
|---|
| 241 | public function get bufferlength():Number { return _bufferlength; } |
|---|
| 242 | public function set bufferlength(x:Number):void { _bufferlength = x; } |
|---|
| 243 | |
|---|
| 244 | /** |
|---|
| 245 | * What to do when one clicks the display. Can be play, link, fullscreen, none, mute, next. When set to none, the handcursor is |
|---|
| 246 | * also not shown. @default play |
|---|
| 247 | **/ |
|---|
| 248 | public function get displayclick():String { return _displayclick; } |
|---|
| 249 | public function set displayclick(x:String):void { _displayclick = x; } |
|---|
| 250 | |
|---|
| 251 | /** Set this to true to print the title of a video in the display. @default true **/ |
|---|
| 252 | public function get displaytitle():Boolean { return _displaytitle; } |
|---|
| 253 | public function set displaytitle(x:Boolean):void { _displaytitle = x; } |
|---|
| 254 | |
|---|
| 255 | /** PlaylistItem that should start to play. Use this to set a specific start-item. @default 0 **/ |
|---|
| 256 | public function get item():Number { return _item; } |
|---|
| 257 | public function set item(x:Number):void { _item = x; } |
|---|
| 258 | |
|---|
| 259 | /** Browserframe where link from the display are opened in. Some possibilities are '_self' (same frame) or '_blank' (new browserwindow). @default _blank **/ |
|---|
| 260 | public function get linktarget():String { return _linktarget; } |
|---|
| 261 | public function set linktarget(x:String):void { _linktarget = x; } |
|---|
| 262 | |
|---|
| 263 | /** Mute all sounds on startup. This value is set in a user cookie, and is retrieved the next time the player loads. **/ |
|---|
| 264 | public function get mute():Boolean { return _mute; } |
|---|
| 265 | public function set mute(x:Boolean):void { _mute = x; } |
|---|
| 266 | |
|---|
| 267 | /** 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 **/ |
|---|
| 268 | public function get repeat():String { return _repeat; } |
|---|
| 269 | public function set repeat(x:String):void { _repeat = x; } |
|---|
| 270 | |
|---|
| 271 | /** Shuffle playback of playlist items. @default false **/ |
|---|
| 272 | public function get shuffle():Boolean { return _shuffle; } |
|---|
| 273 | public function set shuffle(x:Boolean):void { _shuffle = x; } |
|---|
| 274 | |
|---|
| 275 | /** 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 **/ |
|---|
| 276 | public function get smoothing():Boolean { return _smoothing; } |
|---|
| 277 | public function set smoothing(x:Boolean):void { _smoothing = x; } |
|---|
| 278 | |
|---|
| 279 | /** 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 **/ |
|---|
| 280 | public function get stretching():String{ return _stretching; } |
|---|
| 281 | public function set stretching(x:String):void { _stretching = x; } |
|---|
| 282 | |
|---|
| 283 | /** Startup volume of the player. Can be 0 to 100. Is saved in a cookie. @default 90 **/ |
|---|
| 284 | public function get volume():Number { return _volume; } |
|---|
| 285 | public function set volume(x:Number):void { _volume = x; } |
|---|
| 286 | |
|---|
| 287 | |
|---|
| 288 | } |
|---|
| 289 | } |
|---|