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