r25056 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25055‎ | r25056 | r25057 >
Date:15:56, 22 August 2007
Author:tstarling
Status:old
Tags:
Comment:
* (Bug 10949) Fixed java detection
* Fixed a bug with the VLC IE embedding.
Modified paths:
  • /trunk/extensions/OggHandler/OggPlayer.js (modified) (history)

Diff [purge]

Index: trunk/extensions/OggHandler/OggPlayer.js
@@ -14,6 +14,7 @@
1515 'msg': {},
1616 'cortadoUrl' : '',
1717 'showPlayerSelect': true,
 18+ 'controlsHeightGuess': 20,
1819
1920 // Main entry point: initialise a video player
2021 // Player will be created as a child of the given ID
@@ -84,12 +85,20 @@
8586 }
8687 this.detectionDone = true;
8788
 89+ // navigator.javaEnabled() only tells us about preferences, we need to
 90+ // search navigator.mimeTypes to see if it's installed
 91+ var javaEnabled = navigator.javaEnabled();
 92+
8893 // MSIE VLC
89 - try {
90 - var vlcObj = new ActiveXObject( "VideoLAN.VLCPlugin.2" );
 94+ if ( this.testActiveX( 'VideoLAN.VLCPlugin.2' ) ) {
9195 this.clientSupports['vlcActiveX'] = true;
92 - } catch ( e ) {}
 96+ }
9397
 98+ // MSIE Java
 99+ if ( javaEnabled && this.testActiveX( 'JavaPlugin' ) ) {
 100+ this.clientSupports['cortado'] = true;
 101+ }
 102+
94103 // <video> element
95104 elt.innerHTML = '<video id="testvideo"></video>\n';
96105 var testvideo = document.getElementById('testvideo');
@@ -98,6 +107,8 @@
99108 }
100109
101110 // Mozilla plugins
 111+
 112+
102113 if(navigator.mimeTypes && navigator.mimeTypes.length > 0) {
103114 for ( var i = 0; i < navigator.mimeTypes.length; i++) {
104115 var type = navigator.mimeTypes[i].type;
@@ -110,11 +121,24 @@
111122 if(navigator.mimeTypes[i].type.indexOf("application/x-vlc-plugin") > -1) {
112123 this.clientSupports['vlcPlugin'] = true;
113124 }
 125+ if (javaEnabled &&
 126+ navigator.mimeTypes[i].type.indexOf("application/x-java-applet") > -1)
 127+ {
 128+ this.clientSupports['cortado'] = true;
 129+ }
114130 }
115131 }
 132+ },
116133
117 - // Java
118 - this.clientSupports['cortado'] = navigator.javaEnabled();
 134+ 'testActiveX' : function ( name ) {
 135+ var hasObj = true;
 136+ try {
 137+ // No IE, not a class called "name", it's a variable
 138+ var obj = new ActiveXObject( '' + name );
 139+ } catch ( e ) {
 140+ hasObj = false;
 141+ }
 142+ return hasObj;
119143 },
120144
121145 'addOption' : function ( select, value, text, selected ) {
@@ -182,7 +206,7 @@
183207 'embedVideoElement': function ( elt, videoUrl, width, height, length ) {
184208 var videoElt = document.createElement('video');
185209 videoElt.setAttribute( 'width', width );
186 - videoElt.setAttribute( 'height', height + 20 );
 210+ videoElt.setAttribute( 'height', height + this.controlsHeightGuess );
187211 videoElt.setAttribute( 'src', videoUrl );
188212 videoElt.setAttribute( 'autoplay', '1' );
189213 videoElt.setAttribute( 'controls', '1' );
@@ -205,13 +229,13 @@
206230 "<object id=" + this.hq( id ) +
207231 " type='application/ogg'" +
208232 " width=" + this.hq( width ) +
209 - " height=" + this.hq( height + 20 ) +
 233+ " height=" + this.hq( height + this.controlsHeightGuess ) +
210234 " data=" + this.hq( videoUrl ) + "></object>";
211235 },
212236
213237 'embedVlcPlugin' : function ( elt, videoUrl, width, height, length ) {
214238 var id = elt.id + "_obj";
215 - elt.innerHTML +=
 239+ elt.innerHTML +=
216240 "<object id=" + this.hq( id ) +
217241 " type='application/x-vlc-plugin'" +
218242 " width=" + this.hq( width ) +
@@ -229,27 +253,41 @@
230254 'embedVlcActiveX' : function ( elt, videoUrl, width, height, length ) {
231255 var id = elt.id + "_obj";
232256
233 - // I ran into some hairy object initialisation issues when trying to
234 - // create this object with DOM functions. If anyone knows a better way
235 - // than innerHTML, please let me know. -- TS
236 - elt.innerHTML +=
 257+ var html =
237258 '<object id=' + this.hq( id ) +
238259 ' classid="clsid:9BE31822-FDAD-461B-AD51-BE1D1C159921"' +
239260 ' codebase="http://downloads.videolan.org/pub/videolan/vlc/latest/win32/axvlc.cab#Version=0,8,6,0"' +
240261 ' width=' + this.hq( width ) +
241 - ' height=' + this.hq( height ) + ">" +
 262+ ' height=' + this.hq( height ) +
 263+ ' style="width: ' + this.hx( width ) + 'px; height: ' + this.hx( height ) + 'px;"' +
 264+ ">" +
242265 '<param name="mrl" value=' + this.hq( videoUrl ) + '/>' +
243 - '</object>' ;
 266+ '</object>';
 267+ elt.innerHTML += html;
244268
245269 var videoElt = document.getElementById( id );
 270+
 271+ // IE says "sorry, I wasn't listening, what were the dimensions again?"
 272+ if ( width && height ) {
 273+ videoElt.width = width;
 274+ videoElt.height = height;
 275+ videoElt.style.width = width + 'px';
 276+ videoElt.style.height = height + 'px';
 277+ }
 278+
246279 elt.appendChild( document.createElement( 'br' ) );
247280 // TODO: seek bar
248 - elt.appendChild( this.newPlayButton( videoElt.playlist ) );
 281+ elt.appendChild( this.newButton( 'ogg-play', function() { videoElt.playlist.play(); } ) );
249282 // FIXME: playlist.pause() doesn't work
250 - elt.appendChild( this.newStopButton( videoElt.playlist ) );
 283+ elt.appendChild( this.newButton( 'ogg-stop', function() { videoElt.playlist.stop(); } ) );
251284 },
252285
253286 'embedCortado' : function ( elt, videoUrl, width, height, length ) {
 287+ var statusHeight = 18;
 288+ // Given extra vertical space, cortado centres the video and then overlays the status
 289+ // line, leaving an ugly black bar at the top. So we don't give it any.
 290+ var playerHeight = height < statusHeight ? statusHeight : height;
 291+
254292 // Create the applet all at once
255293 // In Opera, document.createElement('applet') immediately creates
256294 // a non-working applet with unchangeable parameters, similar to the
@@ -257,14 +295,14 @@
258296 elt.innerHTML =
259297 '<applet code="com.fluendo.player.Cortado.class" ' +
260298 ' width=' + this.hq( width ) +
261 - ' height=' + this.hq( height + 18 ) +
 299+ ' height=' + this.hq( playerHeight ) +
262300 ' archive=' + this.hq( this.cortadoUrl ) + '>' +
263301 ' <param name="url" value=' + this.hq( videoUrl ) + '/>' +
264302 ' <param name="duration" value=' + this.hq( length ) + '/>' +
265303 ' <param name="seekable" value="true"/>' +
266304 ' <param name="autoPlay" value="true"/>' +
267305 ' <param name="showStatus" value="show"/>' +
268 - ' <param name="statusHeight" value="18"/>' +
 306+ ' <param name="statusHeight" value="' + statusHeight + '"/>' +
269307 '</applet>';
270308
271309 // Disable autoPlay in the DOM right now, to prevent Mozilla from

Status & tagging log