This repository has been archived by the owner on Apr 21, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOggPlayer.js
783 lines (709 loc) · 24.9 KB
/
OggPlayer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
// This is a global configuration object which can embed multiple video instances
var wgOggPlayer = {
'detectionDone': false,
'msie': false,
'safari' : false,
'opera' : false,
'mozilla': false,
'safariControlsBug': false,
// List of players in order of preference
// Downpreffed VLC because it crashes my browser all the damn time -- TS
'players': ['videoElement', 'cortado', 'quicktime-mozilla', 'quicktime-activex', 'vlc-mozilla', 'vlc-activex', 'totem', 'kmplayer', 'kaffeine', 'mplayerplug-in', 'oggPlugin'],
// Client support table
'clientSupports': { 'thumbnail' : true },
// MIME type to be used to invoke a given plugin with <object>
// May be changed by detect()
'mimeTypes' : {
'quicktime-mozilla': 'video/quicktime',
'quicktime-activex': 'video/quicktime',
'vlc-mozilla': 'application/x-vlc-plugin',
'oggPlugin': 'application/ogg',
'totem': 'application/ogg',
'kmplayer': 'application/ogg',
'kaffeine': 'application/ogg',
'mplayerplug-in': 'application/ogg'
},
'savedThumbs': {},
'qtTimers' : {},
// Text for new messages, to support cached HTML invocation
'defaultMsg' : {
'ogg-player-totem': 'Totem',
'ogg-player-kmplayer': 'KMPlayer',
'ogg-player-kaffeine': 'Kaffeine',
'ogg-player-mplayerplug-in': 'mplayerplug-in'
},
// Configuration from MW
'msg': {},
'cortadoUrl' : '',
'extPathUrl' : '',
'showPlayerSelect': true,
'controlsHeightGuess': 20,
/**
* Main entry point: initialise a video player
* Player will be created as a child of the given ID
* There may be multiple players in a document.
* Parameters are: id, videoUrl, width, height, length, linkUrl, isVideo
*/
'init': function ( player, params ) {
// Expand params.videoUrl if protocol-relative
if ( params.videoUrl.substr( 0, 2 ) == '//' ) {
// window.location.protocol is something like 'http:'
params.videoUrl = window.location.protocol + params.videoUrl;
}
elt = document.getElementById( params.id );
// Save still image HTML
if ( !(params.id in this.savedThumbs) ) {
var thumb = document.createDocumentFragment();
for ( i = 0; i < elt.childNodes.length; i++ ) {
thumb.appendChild( elt.childNodes.item( i ).cloneNode( true ) );
}
this.savedThumbs[params.id] = thumb;
}
this.detect();
if ( !player ) {
// See if there is a cookie specifying a preferred player
var cookieVal = this.getCookie( 'ogg_player' );
if ( cookieVal && cookieVal != 'thumbnail' ) {
player = cookieVal;
}
}
if ( !this.clientSupports[player] ) {
player = false;
}
if ( !player ) {
for ( var i = 0; i < this.players.length; i++ ) {
if ( this.clientSupports[this.players[i]] ) {
player = this.players[i];
break;
}
}
}
elt.innerHTML = '';
switch ( player ) {
case 'videoElement':
this.embedVideoElement( elt, params );
break;
case 'oggPlugin':
case 'kaffeine':
case 'totem':
case 'kmplayer':
case 'mplayerplug-in':
this.embedOggPlugin( elt, params, player );
break;
case 'vlc-mozilla':
this.embedVlcPlugin( elt, params );
break;
case 'vlc-activex':
this.embedVlcActiveX( elt, params );
break;
case 'cortado':
this.embedCortado( elt, params );
break;
case 'quicktime-mozilla':
case 'quicktime-activex':
this.embedQuicktimePlugin( elt, params, player );
break;
case 'thumbnail':
default:
if ( params.id in this.savedThumbs ) {
elt.appendChild( this.savedThumbs[params.id].cloneNode( true ) );
} else {
elt.appendChild( document.createTextNode( 'Missing saved thumbnail for ' + params.id ) );
}
if ( player != 'thumbnail' ) {
var div = document.createElement( 'div' );
div.className = 'ogg-player-options';
div.style.cssText = 'width: ' + ( params.width - 10 ) + 'px;';
div.innerHTML = this.msg['ogg-no-player'];
elt.appendChild( div );
player = 'none';
}
}
if ( player != 'thumbnail' ) {
var optionsBox = this.makeOptionsBox( player, params );
var optionsLink = this.makeOptionsLink( params.id );
var div = document.createElement( 'div' );
div.appendChild( optionsBox );
div.appendChild( optionsLink );
elt.appendChild( div );
}
},
'debug': function( s ) {
//alert(s);
},
// Search for a plugin in navigator.plugins
'hasPlugin': function( mimeType ) {
for ( var i = 0; i < navigator.plugins.length; i++ ) {
var plugin = navigator.plugins[i];
if ( typeof plugin[mimeType] != "undefined" ) {
return true;
}
}
return false;
},
// Detect client capabilities
'detect': function() {
if (this.detectionDone) {
return;
}
this.detectionDone = true;
// First some browser detection
this.msie = ( navigator.appName == "Microsoft Internet Explorer" );
this.mozilla = ( navigator.appName == "Netscape" );
this.opera = ( navigator.appName == 'Opera' );
this.safari = ( navigator.vendor && navigator.vendor.substr( 0, 5 ) == 'Apple' );
this.konqueror = ( navigator.appName == 'Konqueror' );
// In Mozilla, navigator.javaEnabled() only tells us about preferences, we need to
// search navigator.mimeTypes to see if it's installed
var javaEnabled = navigator.javaEnabled();
// In Opera, navigator.javaEnabled() is all there is
var invisibleJava = this.opera;
// Opera will switch off javaEnabled in preferences if java can't be found.
// And it doesn't register an application/x-java-applet mime type like Mozilla does.
if ( invisibleJava && javaEnabled ) {
this.clientSupports['cortado'] = true;
}
if ( this.konqueror ) {
// Java is bugged as of 3.5.9
// Applet freezes shortly after starting
javaEnabled = false;
}
if ( this.safari ) {
// Detect https://bugs.webkit.org/show_bug.cgi?id=25575
var match = /AppleWebKit\/([0-9]+)/.exec( navigator.userAgent );
if ( match && parseInt( match[1] ) < 531 ) {
this.safariControlsBug = true;
}
}
// ActiveX plugins
// VLC
if ( this.testActiveX( 'VideoLAN.VLCPlugin.2' ) ) {
this.clientSupports['vlc-activex'] = true;
}
// Java
if ( javaEnabled && this.testActiveX( 'JavaWebStart.isInstalled' ) ) {
this.clientSupports['cortado'] = true;
}
// QuickTime
if ( this.testActiveX( 'QuickTimeCheckObject.QuickTimeCheck.1' ) ) {
this.clientSupports['quicktime-activex'] = true;
}
// <video> element
if ( typeof HTMLVideoElement == 'object' // Firefox, Safari
|| typeof HTMLVideoElement == 'function' ) // Opera
{
// Safari does not support Theora by default, but later versions implement canPlayType()
if ( this.safari ) {
try {
var video = document.createElement( 'video' );
if ( video.canPlayType
&& (video.canPlayType( 'video/ogg;codecs="theora,vorbis"' ) == 'probably' ||
video.canPlayType( 'video/mp4; codecs="avc1.42E01E, mp4a.40.2"' ) == 'probably' ) )
{
this.clientSupports['videoElement'] = true;
} else if ( this.supportedMimeType( 'video/ogg' ) ) {
// On older versions, XiphQT registers a plugin type and also handles <video>
this.clientSupports['videoElement'] = true;
} else {
// TODO: prompt for XiphQT install
}
} catch ( e ) {}
} else {
this.clientSupports['videoElement'] = true;
}
}
if (!navigator.mimeTypes || navigator.mimeTypes.length == 0) {
// No Mozilla plugins, all done
return;
}
// Mozilla plugins
var typesByPlayer = {};
var playersByType = {};
var numPlayersByType = {};
var player;
var i;
for ( i = 0; i < navigator.mimeTypes.length; i++) {
var entry = navigator.mimeTypes[i];
var type = entry.type;
var semicolonPos = type.indexOf( ';' );
if ( semicolonPos > -1 ) {
type = type.substr( 0, semicolonPos );
}
var plugin = entry.enabledPlugin;
// In case it is null or undefined
var pluginName = plugin && plugin.name ? plugin.name : '';
var pluginFilename = plugin && plugin.filename ? plugin.filename : '';
player = '';
if ( javaEnabled && type == 'application/x-java-applet' ) {
// We use <applet> so we don't have to worry about unique types
this.clientSupports['cortado'] = true;
// But it could conflict with another plugin
// Set player='' to avoid double registration of cortado
player = '';
} else if ( pluginFilename.indexOf( 'libtotem' ) > -1 ) {
// Totem
player = 'totem';
} else if ( pluginFilename.indexOf( 'libkmplayerpart' ) > -1 ) {
// KMPlayer is fussy about what type you give it
if ( pluginName == 'Windows Media Player Plugin'
|| pluginName == 'QuickTime Plug-in' )
{
player = 'kmplayer';
}
} else if ( pluginFilename.indexOf( 'kaffeineplugin' ) > -1 ) {
// Kaffeine
player = 'kaffeine';
} else if ( pluginName.indexOf( 'mplayerplug-in' ) > -1 ) {
player = 'mplayerplug-in';
} else if ( pluginFilename.indexOf( 'mplayerplug-in-qt' ) > -1 ) {
// MPlayer fake QuickTime
player = '';
} else if ( pluginName.indexOf( 'QuickTime Plug-in' ) > -1 ) {
// Note: Totem and KMPlayer also use this pluginName, which is
// why we check for them first
player = 'quicktime-mozilla';
} else if ( (pluginName.toLowerCase() == 'vlc multimedia plugin')
|| (pluginName.toLowerCase() == 'vlc multimedia plug-in') )
{
player = 'vlc-mozilla';
} else if ( type == 'application/ogg' ) {
player = 'oggPlugin';
}
if ( this.konqueror && player == 'vlc-mozilla' ) {
// In Konqueror 3.5.9, VLC is not scriptable, has no controls, and crashes the browser
player = '';
}
// Update some hashtables to track unique type assignment
// Slightly complicated because players can and do conflict with themselves
if ( !( player in typesByPlayer ) ) {
typesByPlayer[player] = {};
}
typesByPlayer[player][type] = true;
if ( !( type in playersByType ) ) {
playersByType[type] = {};
numPlayersByType[type] = 0;
}
if ( !( player in playersByType[type] ) ) {
playersByType[type][player] = true;
numPlayersByType[type]++;
}
}
// Determine a unique MIME type for each player found
for ( i = 0; i < this.players.length; i++ ) {
player = this.players[i];
if ( !( player in typesByPlayer ) ) {
continue;
}
// Is the default OK?
var defaultType = this.mimeTypes[player];
if ( defaultType in numPlayersByType
&& numPlayersByType[defaultType] == 1
&& defaultType in typesByPlayer[player] )
{
// Yes, use it
this.debug( player + " -> " + defaultType );
this.clientSupports[player] = true;
continue;
}
// Search for a unique type
for ( var type in typesByPlayer[player] ) {
if ( numPlayersByType[type] == 1 ) {
// Found a unique type
this.mimeTypes[player] = type;
this.clientSupports[player] = true;
this.debug( player + " => " + type );
break;
}
}
if ( !(player in this.clientSupports ) ) {
if ( typesByPlayer[player].length > 0 ) {
this.debug( "No unique MIME type for " + player );
} else {
this.debug( "No types for player " + player );
}
}
}
},
'testActiveX' : function ( name ) {
if ( this.mozilla ) return false;
var hasObj = true;
try {
// No IE, not a class called "name", it's a variable
var obj = new ActiveXObject( '' + name );
} catch ( e ) {
hasObj = false;
}
return hasObj;
},
'addOption' : function ( select, value, text, selected ) {
var option = document.createElement( 'option' );
option.value = value;
option.appendChild( document.createTextNode( text ) );
if ( selected ) {
option.selected = true;
}
select.appendChild( option );
},
'hx' : function ( s ) {
if ( typeof s != 'String' ) {
s = s.toString();
}
return s.replace( /&/g, '&' )
. replace( /</g, '<' )
. replace( />/g, '>' );
},
'hq' : function ( s ) {
return '"' + this.hx( s ) + '"';
},
'getMsg': function ( key ) {
if ( key in this.msg ) {
return this.msg[key];
} else if ( key in this.defaultMsg ) {
return this.defaultMsg[key];
} else {
return '[' + key + ']';
}
},
'makeOptionsBox' : function ( selectedPlayer, params ) {
var div, p, a, ul, li, button;
div = document.createElement( 'div' );
div.style.cssText = "width: " + ( params.width - 10 ) + "px; display: none;";
div.className = 'ogg-player-options';
div.id = params.id + '_options_box';
div.align = 'center';
ul = document.createElement( 'ul' );
// Description page link
if ( params.linkUrl ) {
li = document.createElement( 'li' );
a = document.createElement( 'a' );
a.href = params.linkUrl;
a.appendChild( document.createTextNode( this.msg['ogg-desc-link'] ) );
li.appendChild( a );
ul.appendChild( li );
}
// Download link
li = document.createElement( 'li' );
a = document.createElement( 'a' );
a.href = params.videoUrl;
a.appendChild( document.createTextNode( this.msg['ogg-download'] ) );
li.appendChild( a );
ul.appendChild( li );
div.appendChild( ul );
// Player list caption
p = document.createElement( 'p' );
p.appendChild( document.createTextNode( this.msg['ogg-use-player'] ) );
div.appendChild( p );
// Make player list
ul = document.createElement( 'ul' );
for ( var i = 0; i < this.players.length + 1; i++ ) {
var player, playerMsg;
if ( i == this.players.length ) {
player = 'thumbnail';
if ( params.isVideo ) {
playerMsg = 'ogg-player-thumbnail';
} else {
playerMsg = 'ogg-player-soundthumb';
}
} else {
player = this.players[i];
// Skip unsupported players
if ( ! this.clientSupports[player] ) {
continue;
}
playerMsg = 'ogg-player-' + player;
}
// Make list item
li = document.createElement( 'li' );
if ( player == selectedPlayer ) {
var strong = document.createElement( 'strong' );
strong.appendChild( document.createTextNode(
this.getMsg(playerMsg) + ' ' + this.msg['ogg-player-selected'] ) );
li.appendChild( strong );
} else {
a = document.createElement( 'a' );
a.href = 'javascript:void("' + player + '")';
a.onclick = this.makePlayerFunction( player, params );
a.appendChild( document.createTextNode( this.getMsg(playerMsg) ) );
li.appendChild( a );
}
ul.appendChild( li );
}
div.appendChild( ul );
div2 = document.createElement( 'div' );
div2.style.cssText = 'text-align: center;';
button = document.createElement( 'button' );
button.appendChild( document.createTextNode( this.msg['ogg-dismiss'] ) );
button.onclick = this.makeDismissFunction( params.id );
div2.appendChild( button );
div.appendChild( div2 );
return div;
},
'makeOptionsLink' : function ( id ) {
var a = document.createElement( 'a' );
a.href = 'javascript:void("options")';
a.id = id + '_options_link';
a.onclick = this.makeDisplayOptionsFunction( id );
a.appendChild( document.createTextNode( this.msg['ogg-more'] ) );
return a;
},
'setCssProperty' : function ( elt, prop, value ) {
// Could use style.setProperty() here if it worked in IE
var re = new RegExp( prop + ':[^;](;|$)' );
if ( elt.style.cssText.search( re ) > -1 ) {
elt.style.cssText = elt.style.cssText.replace( re, prop + ':' + value + '$1' );
} else if ( elt.style.cssText == '' ) {
elt.style.cssText = prop + ':' + value + ';';
} else if ( elt.style.cssText[elt.style.cssText.length - 1] == ';' ) {
elt.style.cssText += prop + ':' + value + ';';
} else {
elt.style.cssText += ';' + prop + ':' + value + ';';
}
},
'makeDismissFunction' : function ( id ) {
var this_ = this;
return function () {
var optionsLink = document.getElementById( id + '_options_link' );
var optionsBox = document.getElementById( id + '_options_box' );
this_.setCssProperty( optionsLink, 'display', 'inline' );
this_.setCssProperty( optionsBox, 'display', 'none' );
}
},
'makeDisplayOptionsFunction' : function ( id ) {
var this_ = this;
return function () {
var optionsLink = document.getElementById( id + '_options_link' );
var optionsBox = document.getElementById( id + '_options_box' );
this_.setCssProperty( optionsLink, 'display', 'none' );
this_.setCssProperty( optionsBox, 'display', 'block' );
}
},
'makePlayerFunction' : function ( player, params ) {
var this_ = this;
return function () {
if ( player != 'thumbnail' ) {
var week = 7*86400*1000;
this_.setCookie( 'ogg_player', player, week, false, false, false, false );
}
this_.init( player, params );
};
},
'newButton': function ( caption, image, callback ) {
var elt = document.createElement('input');
elt.type = 'image';
elt.src = this.extPathUrl + '/' + image;
elt.alt = elt.value = elt.title = this.msg[caption];
elt.onclick = callback;
return elt;
},
'newPlayButton': function ( videoElt ) {
return this.newButton( 'ogg-play', 'play.png', function () { videoElt.play(); } );
},
'newPauseButton': function ( videoElt ) {
return this.newButton( 'ogg-pause', 'pause.png', function () { videoElt.pause(); } );
},
'newStopButton': function ( videoElt ) {
return this.newButton( 'ogg-stop', 'stop.png', function () { videoElt.stop(); } );
},
'embedVideoElement': function ( elt, params ) {
var id = elt.id + "_obj";
var tagName = params.isVideo ? 'video' : 'audio';
var html =
'<div><' + tagName +
' id=' + this.hq( id ) +
' width=' + this.hq( params.width ) +
' height=' + this.hq( (params.height>0)?params.height:this.controlsHeightGuess ) +
' autoplay';
if ( !this.safariControlsBug ) {
html += ' controls';
}
html += ' >';
if ( typeof params.mp4Url != 'undefined' && params.mp4Url != false )
html += '<source src=' + this.hq( params.mp4Url ) + " type='video/mp4; codecs=\"avc1.42E01E, mp4a.40.2\"' />";
html += '<source src=' + this.hq( params.videoUrl ) + " type='video/ogg; codecs=\"theora, vorbis\"' \>";
html += '</' + tagName + '></div>';
elt.innerHTML = html;
},
'embedOggPlugin': function ( elt, params, player ) {
var id = elt.id + "_obj";
elt.innerHTML +=
"<div><object id=" + this.hq( id ) +
" type=" + this.hq( this.mimeTypes[player] ) +
" width=" + this.hq( params.width ) +
" height=" + this.hq( params.height + this.controlsHeightGuess ) +
" data=" + this.hq( params.videoUrl ) + "></object></div>";
},
'embedVlcPlugin' : function ( elt, params ) {
var id = elt.id + "_obj";
elt.innerHTML +=
"<div><object id=" + this.hq( id ) +
" type=" + this.hq( this.mimeTypes['vlc-mozilla'] ) +
" width=" + this.hq( params.width ) +
" height=" + this.hq( params.height ) +
" data=" + this.hq( params.videoUrl ) + "></object></div>";
var videoElt = document.getElementById( id );
var div = document.createElement( 'div' );
// TODO: seek bar
div.appendChild( this.newPlayButton( videoElt ) );
div.appendChild( this.newPauseButton( videoElt ) );
div.appendChild( this.newStopButton( videoElt ) );
elt.appendChild( div );
},
'embedVlcActiveX' : function ( elt, params ) {
var id = elt.id + "_obj";
elt.innerHTML =
'<div><object id=' + this.hq( id ) +
' classid="clsid:9BE31822-FDAD-461B-AD51-BE1D1C159921"' +
' codebase="http://downloads.videolan.org/pub/videolan/vlc/latest/win32/axvlc.cab#Version=0,8,6,0"' +
' width=' + this.hq( params.width ) +
' height=' + this.hq( params.height ) +
' style="width: ' + this.hx( params.width ) + 'px; height: ' + this.hx( params.height ) + 'px;"' +
">" +
'<param name="mrl" value=' + this.hq( params.videoUrl ) + '/>' +
'</object></div>';
var videoElt = document.getElementById( id );
// IE says "sorry, I wasn't listening, what were the dimensions again?"
if ( params.width && params.height ) {
videoElt.width = params.width;
videoElt.height = params.height;
videoElt.style.width = params.width + 'px';
videoElt.style.height = params.height + 'px';
}
var div = document.createElement( 'div' );
// TODO: seek bar
div.appendChild( this.newButton( 'ogg-play', 'play.png', function() { videoElt.playlist.play(); } ) );
// FIXME: playlist.pause() doesn't work
div.appendChild( this.newButton( 'ogg-stop', 'stop.png', function() { videoElt.playlist.stop(); } ) );
elt.appendChild( div );
},
'embedCortado' : function ( elt, params ) {
var statusHeight = 18;
var playerHeight = params.height + statusHeight;
// Create the applet all at once
// In Opera, document.createElement('applet') immediately creates
// a non-working applet with unchangeable parameters, similar to the
// problem with IE and ActiveX.
var html =
'<applet code="com.fluendo.player.Cortado.class" ' +
' width=' + this.hq( params.width ) +
' height=' + this.hq( playerHeight ) +
' archive=' + this.hq( this.cortadoUrl ) + '>' +
' <param name="url" value=' + this.hq( params.videoUrl ) + '/>' +
' <param name="duration" value=' + this.hq( params.length ) + '/>' +
' <param name="seekable" value="true"/>' +
' <param name="autoPlay" value="true"/>' +
' <param name="showStatus" value="show"/>' +
' <param name="showSpeaker" value="false"/>' +
' <param name="statusHeight" value="' + statusHeight + '"/>' +
'</applet>';
// Wrap it in an iframe to avoid hanging the event thread in FF 2/3 and similar
// Doesn't work in MSIE or Safari/Mac or Opera 9.5
if ( this.mozilla ) {
var iframe = document.createElement( 'iframe' );
iframe.setAttribute( 'width', params.width );
iframe.setAttribute( 'height', playerHeight );
iframe.setAttribute( 'scrolling', 'no' );
iframe.setAttribute( 'frameborder', 0 );
iframe.setAttribute( 'marginWidth', 0 );
iframe.setAttribute( 'marginHeight', 0 );
elt.appendChild( iframe );
var newDoc = iframe.contentDocument;
newDoc.open();
newDoc.write( '<html><body>' + html + '</body></html>' );
newDoc.close(); // spurious error in some versions of FF, no workaround known
} else {
elt.innerHTML ='<div>' + html + '</div>';
}
},
'embedQuicktimePlugin': function ( elt, params, player ) {
var id = elt.id + "_obj";
var controllerHeight = 16; // by observation
var extraAttribs = '';
if ( player == 'quicktime-activex' ) {
extraAttribs = 'classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"';
}
elt.innerHTML +=
"<div><object id=" + this.hq( id ) +
" type='" + this.mimeTypes[player] + "'" +
" width=" + this.hq( params.width ) +
" height=" + this.hq( params.height + controllerHeight ) +
// See http://svn.wikimedia.org/viewvc/mediawiki?view=rev&revision=25605
" data=" + this.hq( this.extPathUrl + '/null_file.mov' ) +
' ' + extraAttribs +
">" +
// Scale, don't clip
"<param name='SCALE' value='Aspect'/>" +
"<param name='AUTOPLAY' value='True'/>" +
"<param name='src' value=" + this.hq( this.extPathUrl + '/null_file.mov' ) + "/>" +
"<param name='QTSRC' value=" + this.hq( params.videoUrl ) + "/>" +
"</object></div>";
// Poll for completion
var this_ = this;
this.qtTimers[params.id] = window.setInterval( this.makeQuickTimePollFunction( params ), 500 );
},
'makeQuickTimePollFunction' : function ( params ) {
var this_ = this;
return function () {
var elt = document.getElementById( params.id );
var id = params.id + '_obj';
var videoElt = document.getElementById( id );
if ( elt && videoElt ) {
// Detect XiphQT (may throw)
var xiphQtVersion = false, done = false;
try {
xiphQtVersion = videoElt.GetComponentVersion('imdc','XiTh', 'Xiph');
done = true;
} catch ( e ) {}
if ( done ) {
window.clearInterval( this_.qtTimers[params.id] );
if ( !xiphQtVersion || xiphQtVersion == '0.0' ) {
var div = document.createElement( 'div' );
div.className = 'ogg-player-options';
div.style.cssText = 'width:' + ( params.width - 10 ) + 'px;';
div.innerHTML = this_.getMsg( 'ogg-no-xiphqt' );
var optionsDiv = document.getElementById( params.id + '_options_box' );
if ( optionsDiv ) {
elt.insertBefore( div, optionsDiv.parentNode );
} else {
elt.appendChild( div );
}
}
// Disable autoplay on back button
this_.setParam( videoElt, 'AUTOPLAY', 'False' );
}
}
};
},
'addParam': function ( elt, name, value ) {
var param = document.createElement( 'param' );
param.setAttribute( 'name', name );
param.setAttribute( 'value', value );
elt.appendChild( param );
},
'setParam' : function ( elt, name, value ) {
var params = elt.getElementsByTagName( 'param' );
for ( var i = 0; i < params.length; i++ ) {
if ( params[i].name.toLowerCase() == name.toLowerCase() ) {
params[i].value = value;
return;
}
}
this.addParam( elt, name, value );
},
'setCookie' : function ( name, value, expiry, path, domain, secure ) {
var expiryDate = false;
if ( expiry ) {
expiryDate = new Date();
expiryDate.setTime( expiryDate.getTime() + expiry );
}
document.cookie = name + "=" + escape(value) +
(expiryDate ? ("; expires=" + expiryDate.toGMTString()) : "") +
(path ? ("; path=" + path) : "") +
(domain ? ("; domain=" + domain) : "") +
(secure ? "; secure" : "");
},
'getCookie' : function ( cookieName ) {
var m = document.cookie.match( cookieName + '=(.*?)(;|$)' );
return m ? unescape( m[1] ) : false;
}
};
// vim: ts=4 sw=4 noet cindent :