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