| 1 | /**************************************************************************** |
|---|
| 2 | * JW WMV Player version 1.1, created with M$ Silverlight 1.0 |
|---|
| 3 | * |
|---|
| 4 | * This file contains all logic for the JW WMV Player. For a functional setup, |
|---|
| 5 | * the following two files are also needed: |
|---|
| 6 | * - silverlight.js (for instantiating the silverlight plugin) |
|---|
| 7 | * - wmvplayer.xaml (or another XAML skin describing the player graphics) |
|---|
| 8 | * |
|---|
| 9 | * More info: http://www.jeroenwijering.com/?item=JW_WMV_Player |
|---|
| 10 | ****************************************************************************/ |
|---|
| 11 | if(typeof jeroenwijering == "undefined") { |
|---|
| 12 | var jeroenwijering = new Object(); |
|---|
| 13 | jeroenwijering.utils = new Object(); |
|---|
| 14 | } |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | /**************************************************************************** |
|---|
| 26 | * The player wrapper; loads config variables and starts MVC cycle. |
|---|
| 27 | ****************************************************************************/ |
|---|
| 28 | jeroenwijering.Player = function(cnt,src,cfg) { |
|---|
| 29 | this.controller; |
|---|
| 30 | this.model; |
|---|
| 31 | this.view; |
|---|
| 32 | this.configuration = { |
|---|
| 33 | backgroundcolor:'FFFFFF', |
|---|
| 34 | windowless:'false', |
|---|
| 35 | file:'', |
|---|
| 36 | height:'260', |
|---|
| 37 | image:'', |
|---|
| 38 | backcolor:'FFFFFF', |
|---|
| 39 | frontcolor:'000000', |
|---|
| 40 | lightcolor:'000000', |
|---|
| 41 | screencolor:'000000', |
|---|
| 42 | width:'320', |
|---|
| 43 | logo:'', |
|---|
| 44 | overstretch:'false', |
|---|
| 45 | shownavigation:'true', |
|---|
| 46 | showstop:'false', |
|---|
| 47 | showdigits:'true', |
|---|
| 48 | usefullscreen:'true', |
|---|
| 49 | usemute:'false', |
|---|
| 50 | autostart:'false', |
|---|
| 51 | bufferlength:'3', |
|---|
| 52 | duration:'0', |
|---|
| 53 | repeat:'false', |
|---|
| 54 | sender:'', |
|---|
| 55 | start:'0', |
|---|
| 56 | volume:'90', |
|---|
| 57 | link:'', |
|---|
| 58 | linkfromdisplay:'false', |
|---|
| 59 | linktarget:'_self' |
|---|
| 60 | }; |
|---|
| 61 | for(itm in this.configuration) { |
|---|
| 62 | if(cfg[itm] != undefined) { |
|---|
| 63 | if (itm.indexOf('color') > 0) { |
|---|
| 64 | this.configuration[itm] = cfg[itm].substr(cfg[itm].length-6); |
|---|
| 65 | } else { |
|---|
| 66 | this.configuration[itm] = cfg[itm]; |
|---|
| 67 | } |
|---|
| 68 | } |
|---|
| 69 | } |
|---|
| 70 | Silverlight.createObjectEx({ |
|---|
| 71 | source:src, |
|---|
| 72 | parentElement:cnt, |
|---|
| 73 | properties:{ |
|---|
| 74 | width:this.configuration['width'], |
|---|
| 75 | height:this.configuration['height'], |
|---|
| 76 | version:'1.0', |
|---|
| 77 | inplaceInstallPrompt:true, |
|---|
| 78 | isWindowless:this.configuration['windowless'], |
|---|
| 79 | background:'#'+this.configuration['backgroundcolor'] |
|---|
| 80 | }, |
|---|
| 81 | events:{ |
|---|
| 82 | onLoad:this.onLoadHandler, |
|---|
| 83 | onError:null |
|---|
| 84 | }, |
|---|
| 85 | context:this |
|---|
| 86 | }); |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | jeroenwijering.Player.prototype = { |
|---|
| 90 | addListener: function(typ,fcn) { |
|---|
| 91 | this.view.listeners.push({type:typ,func:fcn}); |
|---|
| 92 | }, |
|---|
| 93 | |
|---|
| 94 | getConfig: function() { |
|---|
| 95 | return this.configuration; |
|---|
| 96 | }, |
|---|
| 97 | |
|---|
| 98 | onLoadHandler: function(pid,tgt,sdr) { |
|---|
| 99 | tgt.configuration['sender'] = sdr; |
|---|
| 100 | tgt.controller = new jeroenwijering.Controller(tgt.configuration); |
|---|
| 101 | tgt.view = new jeroenwijering.View(tgt.configuration,tgt.controller); |
|---|
| 102 | tgt.model = new jeroenwijering.Model(tgt.configuration,tgt.controller,tgt.view); |
|---|
| 103 | tgt.controller.startMVC(tgt.view,tgt.model); |
|---|
| 104 | }, |
|---|
| 105 | |
|---|
| 106 | sendEvent: function(typ,prm) { |
|---|
| 107 | switch(typ.toUpperCase()) { |
|---|
| 108 | case 'LINK': |
|---|
| 109 | this.controller.setLink(); |
|---|
| 110 | break; |
|---|
| 111 | case 'LOAD': |
|---|
| 112 | this.controller.setLoad(prm); |
|---|
| 113 | break; |
|---|
| 114 | case 'MUTE': |
|---|
| 115 | this.controller.setMute(); |
|---|
| 116 | break; |
|---|
| 117 | case 'PLAY': |
|---|
| 118 | this.controller.setPlay(); |
|---|
| 119 | break; |
|---|
| 120 | case 'SCRUB': |
|---|
| 121 | this.controller.setScrub(prm); |
|---|
| 122 | break; |
|---|
| 123 | case 'STOP': |
|---|
| 124 | this.controller.setStop(); |
|---|
| 125 | break; |
|---|
| 126 | case 'VOLUME': |
|---|
| 127 | this.controller.setVolume(prm); |
|---|
| 128 | break; |
|---|
| 129 | case 'FULLSCREEN': |
|---|
| 130 | this.controller.setFullscreen(); |
|---|
| 131 | break; |
|---|
| 132 | } |
|---|
| 133 | } |
|---|
| 134 | } |
|---|
| 135 | |
|---|
| 136 | |
|---|
| 137 | |
|---|
| 138 | |
|---|
| 139 | |
|---|
| 140 | |
|---|
| 141 | |
|---|
| 142 | |
|---|
| 143 | |
|---|
| 144 | |
|---|
| 145 | /**************************************************************************** |
|---|
| 146 | * The controller of the player MVC triad, which processes all user input. |
|---|
| 147 | ****************************************************************************/ |
|---|
| 148 | jeroenwijering.Controller = function(cfg) { |
|---|
| 149 | this.configuration = cfg; |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | jeroenwijering.Controller.prototype = { |
|---|
| 153 | startMVC: function(vie,mdl) { |
|---|
| 154 | this.view = vie; |
|---|
| 155 | this.model = mdl; |
|---|
| 156 | if(this.configuration['usemute'] == 'true') { |
|---|
| 157 | this.view.onVolume(0); |
|---|
| 158 | this.view.onMute(true); |
|---|
| 159 | this.model.goVolume(0); |
|---|
| 160 | } else { |
|---|
| 161 | this.view.onVolume(this.configuration['volume']); |
|---|
| 162 | this.model.goVolume(this.configuration['volume']); |
|---|
| 163 | } |
|---|
| 164 | if(this.configuration['autostart'] == 'true') { |
|---|
| 165 | this.model.goStart(); |
|---|
| 166 | } else { |
|---|
| 167 | this.model.goPause(); |
|---|
| 168 | } |
|---|
| 169 | }, |
|---|
| 170 | |
|---|
| 171 | setState: function(old,stt) { |
|---|
| 172 | this.state = stt; |
|---|
| 173 | var pos = this.configuration['start']; |
|---|
| 174 | if(old == 'Closed' && pos > 0) { |
|---|
| 175 | setTimeout(jeroenwijering.utils.delegate(this,this.setScrub),200,pos); |
|---|
| 176 | } |
|---|
| 177 | }, |
|---|
| 178 | |
|---|
| 179 | setLink: function() { |
|---|
| 180 | if (this.configuration['linktarget'].indexOf('javascript:') == 0) { |
|---|
| 181 | return Function(this.configuration['linktarget']).apply(); |
|---|
| 182 | } else if (this.configuration['linktarget'] == '_blank') { |
|---|
| 183 | window.open(this.configuration['link']); |
|---|
| 184 | } else if (this.configuration['linktarget'] != '') { |
|---|
| 185 | window.location = this.configuration['link']; |
|---|
| 186 | } |
|---|
| 187 | }, |
|---|
| 188 | |
|---|
| 189 | setLoad: function(fil) { |
|---|
| 190 | if(this.model.state != "Closed") { |
|---|
| 191 | this.model.goStop(); |
|---|
| 192 | } |
|---|
| 193 | this.configuration['file'] = fil; |
|---|
| 194 | if(this.configuration['autostart'] == 'true') { |
|---|
| 195 | setTimeout(jeroenwijering.utils.delegate(this.model,this.model.goStart),100); |
|---|
| 196 | } |
|---|
| 197 | }, |
|---|
| 198 | |
|---|
| 199 | setMute: function() { |
|---|
| 200 | if(this.configuration['usemute'] == 'true') { |
|---|
| 201 | this.configuration['usemute'] = 'false'; |
|---|
| 202 | this.model.goVolume(this.configuration['volume']); |
|---|
| 203 | this.view.onMute(false); |
|---|
| 204 | } else { |
|---|
| 205 | this.configuration['usemute'] = 'true'; |
|---|
| 206 | this.model.goVolume(0); |
|---|
| 207 | this.view.onMute(true); |
|---|
| 208 | } |
|---|
| 209 | }, |
|---|
| 210 | |
|---|
| 211 | setPlay: function() { |
|---|
| 212 | if(this.state == 'Buffering' || this.state == 'Playing') { |
|---|
| 213 | if(this.configuration['duration'] == 0) { |
|---|
| 214 | this.model.goStop(); |
|---|
| 215 | } else { |
|---|
| 216 | this.model.goPause(); |
|---|
| 217 | } |
|---|
| 218 | } else { |
|---|
| 219 | this.model.goStart(); |
|---|
| 220 | } |
|---|
| 221 | }, |
|---|
| 222 | |
|---|
| 223 | setScrub: function(sec) { |
|---|
| 224 | if(sec < 2) { |
|---|
| 225 | sec = 0; |
|---|
| 226 | } else if (sec > this.configuration['duration']-4) { |
|---|
| 227 | sec = this.configuration['duration']-4; |
|---|
| 228 | } |
|---|
| 229 | if(this.state == 'Buffering' || this.state == 'Playing') { |
|---|
| 230 | this.model.goStart(sec); |
|---|
| 231 | } else { |
|---|
| 232 | this.model.goPause(sec); |
|---|
| 233 | } |
|---|
| 234 | }, |
|---|
| 235 | |
|---|
| 236 | setStop: function() { |
|---|
| 237 | this.model.goStop(); |
|---|
| 238 | }, |
|---|
| 239 | |
|---|
| 240 | setVolume: function(pct) { |
|---|
| 241 | if(pct < 0) { pct = 0; } else if(pct > 100) { pct = 100; } |
|---|
| 242 | this.configuration['volume'] = Math.round(pct); |
|---|
| 243 | this.model.goVolume(pct); |
|---|
| 244 | this.view.onVolume(pct); |
|---|
| 245 | if(this.configuration['usemute'] == 'true') { |
|---|
| 246 | this.configuration['usemute'] = 'false'; |
|---|
| 247 | this.view.onMute(false); |
|---|
| 248 | } |
|---|
| 249 | }, |
|---|
| 250 | |
|---|
| 251 | setFullscreen: function() { |
|---|
| 252 | var fss = !this.configuration['sender'].getHost().content.FullScreen; |
|---|
| 253 | this.configuration['sender'].getHost().content.FullScreen = fss; |
|---|
| 254 | jeroenwijering.utils.delegate(this.view,this.view.onFullscreen); |
|---|
| 255 | } |
|---|
| 256 | } |
|---|
| 257 | |
|---|
| 258 | |
|---|
| 259 | |
|---|
| 260 | |
|---|
| 261 | |
|---|
| 262 | |
|---|
| 263 | |
|---|
| 264 | |
|---|
| 265 | |
|---|
| 266 | |
|---|
| 267 | /**************************************************************************** |
|---|
| 268 | * The view of the player MVC triad, which manages the graphics. |
|---|
| 269 | ****************************************************************************/ |
|---|
| 270 | jeroenwijering.View = function(cfg,ctr) { |
|---|
| 271 | this.configuration = cfg; |
|---|
| 272 | this.listeners = Array(); |
|---|
| 273 | this.controller = ctr; |
|---|
| 274 | this.fstimeout; |
|---|
| 275 | this.fslistener; |
|---|
| 276 | this.display = this.configuration['sender'].findName("PlayerDisplay"); |
|---|
| 277 | this.controlbar = this.configuration['sender'].findName("PlayerControls"); |
|---|
| 278 | this.configuration['sender'].getHost().content.onResize = |
|---|
| 279 | jeroenwijering.utils.delegate(this,this.resizePlayer); |
|---|
| 280 | this.configuration['sender'].getHost().content.onFullScreenChange = |
|---|
| 281 | jeroenwijering.utils.delegate(this,this.onFullscreen); |
|---|
| 282 | this.assignColorsClicks(); |
|---|
| 283 | this.resizePlayer(); |
|---|
| 284 | } |
|---|
| 285 | |
|---|
| 286 | jeroenwijering.View.prototype = { |
|---|
| 287 | onBuffer: function(pct) { |
|---|
| 288 | var snd = this.configuration['sender']; |
|---|
| 289 | if(pct == 0) { |
|---|
| 290 | snd.findName("BufferText").Text = null; |
|---|
| 291 | } else { |
|---|
| 292 | pct < 10 ? pct = "0"+pct: pct = ""+pct; |
|---|
| 293 | snd.findName("BufferText").Text = pct; |
|---|
| 294 | } |
|---|
| 295 | this.delegate('BUFFER',Array(pct)); |
|---|
| 296 | }, |
|---|
| 297 | |
|---|
| 298 | onFullscreen: function(fss) { |
|---|
| 299 | var snd = this.configuration['sender']; |
|---|
| 300 | var fst = snd.getHost().content.FullScreen; |
|---|
| 301 | if(fst) { |
|---|
| 302 | this.fstimeout = setTimeout(jeroenwijering.utils.delegate(this, |
|---|
| 303 | this.hideFSControls),2000); |
|---|
| 304 | this.fslistener = this.display.addEventListener('MouseMove', |
|---|
| 305 | jeroenwijering.utils.delegate(this,this.showFSControls)); |
|---|
| 306 | snd.findName("FullscreenSymbol").Visibility = "Collapsed"; |
|---|
| 307 | snd.findName("FullscreenOffSymbol").Visibility = "Visible"; |
|---|
| 308 | } else { |
|---|
| 309 | clearTimeout(this.fstimeout); |
|---|
| 310 | this.display.removeEventListener("MouseMove",this.fslistener); |
|---|
| 311 | this.controlbar.Visibility = "Visible"; |
|---|
| 312 | this.display.Cursor = "Hand"; |
|---|
| 313 | snd.findName("FullscreenSymbol").Visibility = "Visible"; |
|---|
| 314 | snd.findName("FullscreenOffSymbol").Visibility = "Collapsed"; |
|---|
| 315 | } |
|---|
| 316 | this.resizePlayer(); |
|---|
| 317 | this.delegate('FULLSCREEN'); |
|---|
| 318 | }, |
|---|
| 319 | |
|---|
| 320 | showFSControls: function(sdr,arg) { |
|---|
| 321 | var vbt = sdr.findName('PlayerControls'); |
|---|
| 322 | var yps = arg.GetPosition(vbt).Y; |
|---|
| 323 | clearTimeout(this.fstimeout); |
|---|
| 324 | this.controlbar.Visibility = "Visible"; |
|---|
| 325 | this.display.Cursor = "Hand"; |
|---|
| 326 | if(yps < 0) { |
|---|
| 327 | this.fstimeout = setTimeout(jeroenwijering.utils.delegate(this, |
|---|
| 328 | this.hideFSControls),2000); |
|---|
| 329 | } |
|---|
| 330 | }, |
|---|
| 331 | |
|---|
| 332 | hideFSControls: function() { |
|---|
| 333 | this.controlbar.Visibility = "Collapsed"; |
|---|
| 334 | this.display.Cursor = "None"; |
|---|
| 335 | }, |
|---|
| 336 | |
|---|
| 337 | onLoad: function(pct) { |
|---|
| 338 | var snd = this.configuration['sender']; |
|---|
| 339 | var max = snd.findName("TimeSlider").Width; |
|---|
| 340 | snd.findName("DownloadProgress").Width = Math.round(max*pct/100); |
|---|
| 341 | this.delegate('LOAD',Array(pct)); |
|---|
| 342 | }, |
|---|
| 343 | |
|---|
| 344 | onMute: function(mut) { |
|---|
| 345 | var snd = this.configuration['sender']; |
|---|
| 346 | this.configuration['usemute'] = ''+mut; |
|---|
| 347 | if(mut) { |
|---|
| 348 | snd.findName("VolumeHighlight").Visibility = "Collapsed"; |
|---|
| 349 | snd.findName("MuteSymbol").Visibility = "Visible"; |
|---|
| 350 | snd.findName("MuteOffSymbol").Visibility = "Collapsed"; |
|---|
| 351 | if(this.state == 'Playing') { |
|---|
| 352 | snd.findName("MuteIcon").Visibility = "Visible"; |
|---|
| 353 | } |
|---|
| 354 | } else { |
|---|
| 355 | snd.findName("VolumeHighlight").Visibility = "Visible"; |
|---|
| 356 | snd.findName("MuteSymbol").Visibility = "Collapsed"; |
|---|
| 357 | snd.findName("MuteOffSymbol").Visibility = "Visible"; |
|---|
| 358 | snd.findName("MuteIcon").Visibility = "Collapsed"; |
|---|
| 359 | } |
|---|
| 360 | this.delegate('MUTE'); |
|---|
| 361 | }, |
|---|
| 362 | |
|---|
| 363 | onState: function(old,stt) { |
|---|
| 364 | var snd = this.configuration['sender']; |
|---|
| 365 | this.state = stt; |
|---|
| 366 | if(stt == 'Buffering' || stt == 'Playing' || stt == 'Opening') { |
|---|
| 367 | snd.findName("PlayIcon").Visibility = "Collapsed"; |
|---|
| 368 | snd.findName("PlaySymbol").Visibility = "Collapsed"; |
|---|
| 369 | snd.findName("PlayOffSymbol").Visibility = "Visible"; |
|---|
| 370 | if (stt=='Playing') { |
|---|
| 371 | snd.findName("BufferIcon").Visibility = "Collapsed"; |
|---|
| 372 | snd.findName("BufferText").Visibility = "Collapsed"; |
|---|
| 373 | if(this.configuration['usemute'] == 'true') { |
|---|
| 374 | snd.findName("MuteIcon").Visibility = "Visible"; |
|---|
| 375 | } |
|---|
| 376 | } else{ |
|---|
| 377 | snd.findName("BufferIcon").Visibility = "Visible"; |
|---|
| 378 | snd.findName("BufferText").Visibility = "Visible"; |
|---|
| 379 | } |
|---|
| 380 | } else { |
|---|
| 381 | snd.findName("MuteIcon").Visibility = "Collapsed"; |
|---|
| 382 | snd.findName("BufferIcon").Visibility = "Collapsed"; |
|---|
| 383 | snd.findName("BufferText").Visibility = "Collapsed"; |
|---|
| 384 | snd.findName("PlayOffSymbol").Visibility = "Collapsed"; |
|---|
| 385 | snd.findName("PlaySymbol").Visibility = "Visible"; |
|---|
| 386 | if(this.configuration['linkfromdisplay'] == 'true') { |
|---|
| 387 | snd.findName("PlayIcon").Visibility = "Collapsed"; |
|---|
| 388 | } else { |
|---|
| 389 | snd.findName("PlayIcon").Visibility = "Visible"; |
|---|
| 390 | } |
|---|
| 391 | } |
|---|
| 392 | try { |
|---|
| 393 | if(!(old == 'Completed' && stt == 'Buffering') && |
|---|
| 394 | !(old == 'Buffering' && stt == 'Paused')) { |
|---|
| 395 | playerStatusChange(old.toUpperCase(),stt.toUpperCase()); |
|---|
| 396 | } |
|---|
| 397 | } catch (err) {} |
|---|
| 398 | this.delegate('STATE',Array(old,stt)); |
|---|
| 399 | }, |
|---|
| 400 | |
|---|
| 401 | onTime: function(elp,dur) { |
|---|
| 402 | var snd = this.configuration['sender']; |
|---|
| 403 | var snd = this.configuration['sender']; |
|---|
| 404 | var max = snd.findName("TimeSlider").Width; |
|---|
| 405 | if(dur > 0) { |
|---|
| 406 | var pos = Math.round(max*elp/dur); |
|---|
| 407 | this.configuration['duration'] = dur; |
|---|
| 408 | snd.findName("ElapsedText").Text = jeroenwijering.utils.timestring(elp); |
|---|
| 409 | snd.findName("RemainingText").Text = jeroenwijering.utils.timestring(dur-elp); |
|---|
| 410 | snd.findName("TimeSymbol").Visibility = "Visible"; |
|---|
| 411 | snd.findName("TimeSymbol")['Canvas.Left'] = pos+4; |
|---|
| 412 | snd.findName("TimeHighlight").Width = pos-2; |
|---|
| 413 | } else { |
|---|
| 414 | snd.findName("TimeSymbol").Visibility = "Collapsed"; |
|---|
| 415 | } |
|---|
| 416 | this.delegate('TIME',Array(elp,dur)); |
|---|
| 417 | }, |
|---|
| 418 | |
|---|
| 419 | onVolume: function(pct) { |
|---|
| 420 | var snd = this.configuration['sender']; |
|---|
| 421 | snd.findName("VolumeHighlight").Width = Math.round(pct/5); |
|---|
| 422 | this.delegate('VOLUME',Array(pct)); |
|---|
| 423 | }, |
|---|
| 424 | |
|---|
| 425 | assignColorsClicks: function() { |
|---|
| 426 | this.display.Cursor = "Hand"; |
|---|
| 427 | this.display.Background = "#FF"+this.configuration['screencolor']; |
|---|
| 428 | if(this.configuration['linkfromdisplay'] == 'false') { |
|---|
| 429 | this.display.addEventListener('MouseLeftButtonUp', |
|---|
| 430 | jeroenwijering.utils.delegate(this.controller, |
|---|
| 431 | this.controller.setPlay)); |
|---|
| 432 | } else { |
|---|
| 433 | this.display.addEventListener('MouseLeftButtonUp', |
|---|
| 434 | jeroenwijering.utils.delegate(this.controller, |
|---|
| 435 | this.controller.setLink)); |
|---|
| 436 | this.display.findName("PlayIcon").Visibility = "Collapsed"; |
|---|
| 437 | } |
|---|
| 438 | if(this.configuration['logo'] != '') { |
|---|
| 439 | this.display.findName('OverlayCanvas').Visibility = "Visible"; |
|---|
| 440 | this.display.findName('OverlayLogo').ImageSource = |
|---|
| 441 | this.configuration['logo']; |
|---|
| 442 | } |
|---|
| 443 | this.controlbar.findName("ControlbarBack").Fill = |
|---|
| 444 | "#FF"+this.configuration['backcolor']; |
|---|
| 445 | this.assignButton('Play',this.controller.setPlay); |
|---|
| 446 | this.assignButton('Stop',this.controller.setStop); |
|---|
| 447 | this.configuration['sender'].findName('ElapsedText').Foreground = |
|---|
| 448 | "#FF"+this.configuration['frontcolor']; |
|---|
| 449 | this.assignSlider('Time',this.changeTime); |
|---|
| 450 | this.configuration['sender'].findName('DownloadProgress').Fill = |
|---|
| 451 | "#FF"+this.configuration['frontcolor']; |
|---|
| 452 | this.configuration['sender'].findName('RemainingText').Foreground = |
|---|
| 453 | "#FF"+this.configuration['frontcolor']; |
|---|
| 454 | this.assignButton('Link',this.controller.setLink); |
|---|
| 455 | this.assignButton('Fullscreen',this.controller.setFullscreen); |
|---|
| 456 | this.assignButton('Mute',this.controller.setMute); |
|---|
| 457 | this.assignSlider('Volume',this.changeVolume); |
|---|
| 458 | }, |
|---|
| 459 | |
|---|
| 460 | assignButton: function(btn,act) { |
|---|
| 461 | var el1 = this.configuration['sender'].findName(btn+'Button'); |
|---|
| 462 | el1.Cursor = "Hand"; |
|---|
| 463 | el1.addEventListener('MouseLeftButtonUp', |
|---|
| 464 | jeroenwijering.utils.delegate(this.controller,act)); |
|---|
| 465 | el1.addEventListener('MouseEnter', |
|---|
| 466 | jeroenwijering.utils.delegate(this,this.rollOver)); |
|---|
| 467 | el1.addEventListener('MouseLeave', |
|---|
| 468 | jeroenwijering.utils.delegate(this,this.rollOut)); |
|---|
| 469 | this.configuration['sender'].findName(btn+'Symbol').Fill = |
|---|
| 470 | "#FF"+this.configuration['frontcolor']; |
|---|
| 471 | try { |
|---|
| 472 | this.configuration['sender'].findName(btn+'OffSymbol').Fill = |
|---|
| 473 | "#FF"+this.configuration['frontcolor']; |
|---|
| 474 | } catch(e) {} |
|---|
| 475 | }, |
|---|
| 476 | |
|---|
| 477 | assignSlider: function(sld,act) { |
|---|
| 478 | var el1 = this.configuration['sender'].findName(sld+'Button'); |
|---|
| 479 | el1.Cursor = "Hand"; |
|---|
| 480 | el1.addEventListener('MouseLeftButtonUp', |
|---|
| 481 | jeroenwijering.utils.delegate(this,act)); |
|---|
| 482 | el1.addEventListener('MouseEnter', |
|---|
| 483 | jeroenwijering.utils.delegate(this,this.rollOver)); |
|---|
| 484 | el1.addEventListener('MouseLeave', |
|---|
| 485 | jeroenwijering.utils.delegate(this,this.rollOut)); |
|---|
| 486 | this.configuration['sender'].findName(sld+'Slider').Fill = |
|---|
| 487 | "#FF"+this.configuration['frontcolor']; |
|---|
| 488 | this.configuration['sender'].findName(sld+'Highlight').Fill = |
|---|
| 489 | "#FF"+this.configuration['frontcolor']; |
|---|
| 490 | this.configuration['sender'].findName(sld+'Symbol').Fill = |
|---|
| 491 | "#FF"+this.configuration['frontcolor']; |
|---|
| 492 | }, |
|---|
| 493 | |
|---|
| 494 | delegate: function(typ,arg) { |
|---|
| 495 | for(var i=0; i<this.listeners.length; i++) { |
|---|
| 496 | if(this.listeners[i]['type'].toUpperCase() == typ) { |
|---|
| 497 | this.listeners[i]['func'].apply(null,arg); |
|---|
| 498 | } |
|---|
| 499 | } |
|---|
| 500 | }, |
|---|
| 501 | |
|---|
| 502 | rollOver: function(sdr) { |
|---|
| 503 | var str = sdr.Name.substr(0,sdr.Name.length-6); |
|---|
| 504 | this.configuration['sender'].findName(str+'Symbol').Fill = |
|---|
| 505 | "#FF"+this.configuration['lightcolor']; |
|---|
| 506 | try { |
|---|
| 507 | this.configuration['sender'].findName(str+'OffSymbol').Fill = |
|---|
| 508 | "#FF"+this.configuration['lightcolor']; |
|---|
| 509 | } catch(e) {} |
|---|
| 510 | }, |
|---|
| 511 | |
|---|
| 512 | rollOut: function(sdr) { |
|---|
| 513 | var str = sdr.Name.substr(0,sdr.Name.length-6); |
|---|
| 514 | this.configuration['sender'].findName(str+'Symbol').Fill = |
|---|
| 515 | "#FF"+this.configuration['frontcolor']; |
|---|
| 516 | try { |
|---|
| 517 | this.configuration['sender'].findName(str+'OffSymbol').Fill = |
|---|
| 518 | "#FF"+this.configuration['frontcolor']; |
|---|
| 519 | } catch(e) {} |
|---|
| 520 | }, |
|---|
| 521 | |
|---|
| 522 | changeTime: function(sdr,arg) { |
|---|
| 523 | var tbt = sdr.findName('TimeSlider'); |
|---|
| 524 | var xps = arg.GetPosition(tbt).X; |
|---|
| 525 | var sec = Math.floor(xps/tbt.Width*this.configuration['duration']); |
|---|
| 526 | this.controller.setScrub(sec); |
|---|
| 527 | }, |
|---|
| 528 | |
|---|
| 529 | changeVolume: function(sdr,arg) { |
|---|
| 530 | var vbt = sdr.findName('VolumeButton'); |
|---|
| 531 | var xps = arg.GetPosition(vbt).X; |
|---|
| 532 | this.controller.setVolume(xps*5); |
|---|
| 533 | }, |
|---|
| 534 | |
|---|
| 535 | resizePlayer: function() { |
|---|
| 536 | var wid = this.configuration['sender'].getHost().content.actualWidth; |
|---|
| 537 | var hei = this.configuration['sender'].getHost().content.actualHeight; |
|---|
| 538 | var fss = this.configuration['sender'].getHost().content.FullScreen; |
|---|
| 539 | if(this.configuration['shownavigation'] == 'true') { |
|---|
| 540 | if(fss == true) { |
|---|
| 541 | this.resizeDisplay(wid,hei); |
|---|
| 542 | this.controlbar['Canvas.Left'] = Math.round(wid/2-250); |
|---|
| 543 | this.resizeControlbar(500,hei-this.controlbar.Height-16); |
|---|
| 544 | this.controlbar.findName('ControlbarBack')['Opacity'] = 0.5; |
|---|
| 545 | } else { |
|---|
| 546 | this.resizeDisplay(wid,hei-20); |
|---|
| 547 | this.controlbar['Canvas.Left'] = 0; |
|---|
| 548 | this.resizeControlbar(wid,hei-this.controlbar.Height); |
|---|
| 549 | this.controlbar.findName('ControlbarBack')['Opacity'] = 1; |
|---|
| 550 | } |
|---|
| 551 | } else { |
|---|
| 552 | this.resizeDisplay(wid,hei); |
|---|
| 553 | } |
|---|
| 554 | }, |
|---|
| 555 | |
|---|
| 556 | resizeDisplay: function(wid,hei) { |
|---|
| 557 | this.stretchElement('PlayerDisplay',wid,hei); |
|---|
| 558 | this.stretchElement('VideoWindow',wid,hei); |
|---|
| 559 | this.stretchElement('PlaceholderImage',wid,hei); |
|---|
| 560 | this.centerElement('PlayIcon',wid,hei); |
|---|
| 561 | this.centerElement('MuteIcon',wid,hei); |
|---|
| 562 | this.centerElement('BufferIcon',wid,hei); |
|---|
| 563 | this.centerElement('BufferText',wid,hei); |
|---|
| 564 | this.display.findName('OverlayCanvas')['Canvas.Left'] = wid - |
|---|
| 565 | this.display.findName('OverlayCanvas').Width - 10; |
|---|
| 566 | this.display.Visibility = "Visible"; |
|---|
| 567 | }, |
|---|
| 568 | |
|---|
| 569 | resizeControlbar: function(wid,yps,alp) { |
|---|
| 570 | this.controlbar['Canvas.Top'] = yps; |
|---|
| 571 | this.stretchElement('PlayerControls',wid); |
|---|
| 572 | this.stretchElement('ControlbarBack',wid); |
|---|
| 573 | this.placeElement('PlayButton',0); |
|---|
| 574 | var lft = 17; |
|---|
| 575 | this.placeElement('VolumeButton',wid-24); |
|---|
| 576 | this.placeElement('MuteButton',wid-37); |
|---|
| 577 | var rgt = 37; |
|---|
| 578 | if(this.configuration['showstop'] == 'true') { |
|---|
| 579 | this.placeElement('StopButton',lft); |
|---|
| 580 | lft += 17; |
|---|
| 581 | } else { |
|---|
| 582 | this.controlbar.findName('StopButton').Visibility="Collapsed"; |
|---|
| 583 | } |
|---|
| 584 | if(this.configuration['usefullscreen'] == 'true') { |
|---|
| 585 | rgt += 18; |
|---|
| 586 | this.placeElement('FullscreenButton',wid-rgt); |
|---|
| 587 | } else { |
|---|
| 588 | this.controlbar.findName('FullscreenButton').Visibility = |
|---|
| 589 | "Collapsed"; |
|---|
| 590 | } |
|---|
| 591 | if(this.configuration['link'] != '') { |
|---|
| 592 | rgt += 18; |
|---|
| 593 | this.placeElement('LinkButton',wid-rgt); |
|---|
| 594 | } else { |
|---|
| 595 | this.controlbar.findName('LinkButton').Visibility="Collapsed"; |
|---|
| 596 | } |
|---|
| 597 | if(this.configuration['showdigits'] == 'true' && wid-rgt-lft> 160) { |
|---|
| 598 | rgt += 35; |
|---|
| 599 | this.controlbar.findName('RemainingButton').Visibility="Visible"; |
|---|
| 600 | this.controlbar.findName('ElapsedButton').Visibility="Visible"; |
|---|
| 601 | this.placeElement('RemainingButton',wid-rgt); |
|---|
| 602 | this.placeElement('ElapsedButton',lft); |
|---|
| 603 | lft +=35; |
|---|
| 604 | } else { |
|---|
| 605 | this.controlbar.findName('RemainingButton').Visibility = |
|---|
| 606 | "Collapsed"; |
|---|
| 607 | this.controlbar.findName('ElapsedButton').Visibility="Collapsed"; |
|---|
| 608 | } |
|---|
| 609 | this.placeElement('TimeButton',lft); |
|---|
| 610 | this.stretchElement('TimeButton',wid-lft-rgt); |
|---|
| 611 | this.stretchElement('TimeShadow',wid-lft-rgt); |
|---|
| 612 | this.stretchElement('TimeStroke',wid-lft-rgt); |
|---|
| 613 | this.stretchElement('TimeFill',wid-lft-rgt); |
|---|
| 614 | this.stretchElement('TimeSlider',wid-lft-rgt-10); |
|---|
| 615 | this.stretchElement('DownloadProgress',wid-lft-rgt-10); |
|---|
| 616 | var tsb = this.configuration['sender'].findName('TimeSymbol'); |
|---|
| 617 | this.stretchElement('TimeHighlight',tsb['Canvas.Left']-5); |
|---|
| 618 | this.controlbar.Visibility = "Visible"; |
|---|
| 619 | }, |
|---|
| 620 | |
|---|
| 621 | centerElement: function(nam,wid,hei) { |
|---|
| 622 | var elm = this.configuration['sender'].findName(nam); |
|---|
| 623 | elm['Canvas.Left'] = Math.round(wid/2 - elm.Width/2); |
|---|
| 624 | elm['Canvas.Top'] = Math.round(hei/2 - elm.Height/2); |
|---|
| 625 | }, |
|---|
| 626 | |
|---|
| 627 | stretchElement: function(nam,wid,hei) { |
|---|
| 628 | var elm = this.configuration['sender'].findName(nam); |
|---|
| 629 | elm.Width = wid; |
|---|
| 630 | if (hei != undefined) { elm.Height = hei; } |
|---|
| 631 | }, |
|---|
| 632 | |
|---|
| 633 | placeElement: function(nam,xps,yps) { |
|---|
| 634 | var elm = this.configuration['sender'].findName(nam); |
|---|
| 635 | elm['Canvas.Left'] = xps; |
|---|
| 636 | if(yps) { elm['Canvas.Top'] = yps; } |
|---|
| 637 | } |
|---|
| 638 | } |
|---|
| 639 | |
|---|
| 640 | |
|---|
| 641 | |
|---|
| 642 | |
|---|
| 643 | |
|---|
| 644 | |
|---|
| 645 | |
|---|
| 646 | |
|---|
| 647 | |
|---|
| 648 | |
|---|
| 649 | /**************************************************************************** |
|---|
| 650 | * The model of the player MVC triad, which stores all playback logic. |
|---|
| 651 | ****************************************************************************/ |
|---|
| 652 | jeroenwijering.Model = function(cfg,ctr,vie) { |
|---|
| 653 | this.configuration = cfg; |
|---|
| 654 | this.controller = ctr; |
|---|
| 655 | this.view = vie; |
|---|
| 656 | this.video = this.configuration['sender'].findName("VideoWindow"); |
|---|
| 657 | this.preview = this.configuration['sender'].findName("PlaceholderImage"); |
|---|
| 658 | var str = { |
|---|
| 659 | 'true':'UniformToFill', |
|---|
| 660 | 'false':'Uniform', |
|---|
| 661 | 'fit':'Fill', |
|---|
| 662 | 'none':'None' |
|---|
| 663 | } |
|---|
| 664 | this.state = this.video.CurrentState; |
|---|
| 665 | this.timeint; |
|---|
| 666 | this.video.Stretch = str[this.configuration['overstretch']]; |
|---|
| 667 | this.preview.Stretch = str[this.configuration['overstretch']]; |
|---|
| 668 | this.video.BufferingTime = |
|---|
| 669 | jeroenwijering.utils.spanstring(this.configuration['bufferlength']); |
|---|
| 670 | this.video.AutoPlay = true; |
|---|
| 671 | this.video.AddEventListener("CurrentStateChanged", |
|---|
| 672 | jeroenwijering.utils.delegate(this,this.stateChanged)); |
|---|
| 673 | this.video.AddEventListener("MediaEnded", |
|---|
| 674 | jeroenwijering.utils.delegate(this,this.mediaEnded)); |
|---|
| 675 | this.video.AddEventListener("BufferingProgressChanged", |
|---|
| 676 | jeroenwijering.utils.delegate(this,this.bufferChanged)); |
|---|
| 677 | this.video.AddEventListener("DownloadProgressChanged", |
|---|
| 678 | jeroenwijering.utils.delegate(this,this.downloadChanged)); |
|---|
| 679 | if(this.configuration['image'] != '') { |
|---|
| 680 | this.preview.Source = this.configuration['image']; |
|---|
| 681 | } |
|---|
| 682 | } |
|---|
| 683 | |
|---|
| 684 | jeroenwijering.Model.prototype = { |
|---|
| 685 | goPause: function(sec) { |
|---|
| 686 | this.video.pause(); |
|---|
| 687 | if(!isNaN(sec)) { |
|---|
| 688 | this.video.Position = jeroenwijering.utils.spanstring(sec); |
|---|
| 689 | } |
|---|
| 690 | this.timeChanged(); |
|---|
| 691 | }, |
|---|
| 692 | |
|---|
| 693 | goStart: function(sec) { |
|---|
| 694 | this.video.Visibility = 'Visible'; |
|---|
| 695 | this.preview.Visibility = 'Collapsed'; |
|---|
| 696 | if(this.state == "Closed") { |
|---|
| 697 | this.video.Source = this.configuration['file']; |
|---|
| 698 | } else { |
|---|
| 699 | this.video.play(); |
|---|
| 700 | } |
|---|
| 701 | if(!isNaN(sec)) { |
|---|
| 702 | this.video.Position = jeroenwijering.utils.spanstring(sec); |
|---|
| 703 | } |
|---|
| 704 | }, |
|---|
| 705 | |
|---|
| 706 | goStop: function() { |
|---|
| 707 | this.video.Visibility = 'Collapsed'; |
|---|
| 708 | this.preview.Visibility = 'Visible'; |
|---|
| 709 | this.goPause(0); |
|---|
| 710 | this.video.Source = 'null'; |
|---|
| 711 | this.view.onBuffer(0); |
|---|
| 712 | clearInterval(this.timeint); |
|---|
| 713 | }, |
|---|
| 714 | |
|---|
| 715 | goVolume: function(pct) { |
|---|
| 716 | this.video.Volume = pct/100; |
|---|
| 717 | }, |
|---|
| 718 | |
|---|
| 719 | stateChanged: function() { |
|---|
| 720 | var stt = this.video.CurrentState; |
|---|
| 721 | if(stt != this.state) { |
|---|
| 722 | this.controller.setState(this.state,stt); |
|---|
| 723 | this.view.onState(this.state,stt); |
|---|
| 724 | this.state = stt; |
|---|
| 725 | this.configuration['duration'] = |
|---|
| 726 | Math.round(this.video.NaturalDuration.Seconds*10)/10; |
|---|
| 727 | if(stt != "Playing" && stt != "Buffering" && stt != "Opening") { |
|---|
| 728 | clearInterval(this.timeint); |
|---|
| 729 | } else { |
|---|
| 730 | this.timeint = setInterval(jeroenwijering.utils.delegate( |
|---|
| 731 | this,this.timeChanged),100); |
|---|
| 732 | } |
|---|
| 733 | } |
|---|
| 734 | }, |
|---|
| 735 | |
|---|
| 736 | mediaEnded: function() { |
|---|
| 737 | if(this.configuration['repeat'] == 'true') { |
|---|
| 738 | this.goStart(0); |
|---|
| 739 | } else { |
|---|
| 740 | this.state = 'Completed'; |
|---|
| 741 | this.view.onState(this.state,'Completed'); |
|---|
| 742 | this.video.Visibility = 'Collapsed'; |
|---|
| 743 | this.preview.Visibility = 'Visible'; |
|---|
| 744 | this.goPause(0); |
|---|
| 745 | } |
|---|
| 746 | }, |
|---|
| 747 | |
|---|
| 748 | bufferChanged: function() { |
|---|
| 749 | var bfr = Math.round(this.video.BufferingProgress*100); |
|---|
| 750 | this.view.onBuffer(bfr); |
|---|
| 751 | }, |
|---|
| 752 | |
|---|
| 753 | downloadChanged: function() { |
|---|
| 754 | var dld = Math.round(this.video.DownloadProgress*100); |
|---|
| 755 | this.view.onLoad(dld); |
|---|
| 756 | }, |
|---|
| 757 | |
|---|
| 758 | timeChanged: function() { |
|---|
| 759 | var pos = Math.round(this.video.Position.Seconds*10)/10; |
|---|
| 760 | this.view.onTime(pos,this.configuration['duration']); |
|---|
| 761 | } |
|---|
| 762 | } |
|---|
| 763 | |
|---|
| 764 | |
|---|
| 765 | |
|---|
| 766 | |
|---|
| 767 | |
|---|
| 768 | |
|---|
| 769 | |
|---|
| 770 | |
|---|
| 771 | |
|---|
| 772 | |
|---|
| 773 | /**************************************************************************** |
|---|
| 774 | * Some utility functions. |
|---|
| 775 | ****************************************************************************/ |
|---|
| 776 | jeroenwijering.utils.delegate = function(obj,fcn) { |
|---|
| 777 | return function() { |
|---|
| 778 | return fcn.apply(obj,arguments); |
|---|
| 779 | } |
|---|
| 780 | } |
|---|
| 781 | jeroenwijering.utils.timestring = function(stp) { |
|---|
| 782 | var hrs = Math.floor(stp/3600); |
|---|
| 783 | var min = Math.floor(stp%3600/60); |
|---|
| 784 | var sec = Math.round(stp%60); |
|---|
| 785 | var str = ""; |
|---|
| 786 | sec > 9 ? str += sec: str +='0'+sec; |
|---|
| 787 | min > 9 ? str = min+":"+str: str='0'+min+":"+str; |
|---|
| 788 | hrs > 0 ? str = hrs+":"+str: null; |
|---|
| 789 | return str; |
|---|
| 790 | } |
|---|
| 791 | jeroenwijering.utils.spanstring = function(stp) { |
|---|
| 792 | var hrs = Math.floor(stp/3600); |
|---|
| 793 | var min = Math.floor(stp%3600/60); |
|---|
| 794 | var sec = Math.round(stp%60*10)/10; |
|---|
| 795 | var str = hrs+':'+min+':'+sec; |
|---|
| 796 | return str; |
|---|
| 797 | } |
|---|