root/trunk/sl1/player.js @ 41

Revision 41, 21.6 kB (checked in by jeroen, 16 months ago)

1.1 silverlight fixes

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