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