Index: trunk/extensions/OggHandler/OggPlayer.js |
— | — | @@ -5,6 +5,7 @@ |
6 | 6 | 'safari' : false, |
7 | 7 | 'opera' : false, |
8 | 8 | 'mozilla': false, |
| 9 | + 'safariControlsBug': false, |
9 | 10 | |
10 | 11 | // List of players in order of preference |
11 | 12 | // Downpreffed VLC because it crashes my browser all the damn time -- TS |
— | — | @@ -71,7 +72,7 @@ |
72 | 73 | } |
73 | 74 | } |
74 | 75 | |
75 | | - if ( !this.clientSupports[player] ) { |
| 76 | + if ( !this.clientSupports[player] ) { |
76 | 77 | player = false; |
77 | 78 | } |
78 | 79 | |
— | — | @@ -134,17 +135,22 @@ |
135 | 136 | elt.appendChild( div ); |
136 | 137 | } |
137 | 138 | }, |
| 139 | + |
138 | 140 | 'debug': function( s ) { |
139 | 141 | //alert(s); |
140 | 142 | }, |
141 | | - 'supportedMimeType': function(mimetype) { |
142 | | - for (var i = navigator.plugins.length; i-- > 0; ) { |
143 | | - var plugin = navigator.plugins[i]; |
144 | | - if (typeof plugin[mimetype] != "undefined") |
145 | | - return true; |
| 143 | + |
| 144 | + // Search for a plugin in navigator.plugins |
| 145 | + 'hasPlugin': function( mimeType ) { |
| 146 | + for ( var i = 0; i < navigator.plugins.length; i++ ) { |
| 147 | + var plugin = navigator.plugins[i]; |
| 148 | + if ( typeof plugin[mimeType] != "undefined" ) { |
| 149 | + return true; |
| 150 | + } |
146 | 151 | } |
147 | 152 | return false; |
148 | 153 | }, |
| 154 | + |
149 | 155 | // Detect client capabilities |
150 | 156 | 'detect': function() { |
151 | 157 | if (this.detectionDone) { |
— | — | @@ -172,11 +178,22 @@ |
173 | 179 | } |
174 | 180 | |
175 | 181 | if ( this.konqueror ) { |
176 | | - // Bugged as of 3.5.9 |
| 182 | + // Java is bugged as of 3.5.9 |
177 | 183 | // Applet freezes shortly after starting |
178 | 184 | javaEnabled = false; |
179 | 185 | } |
180 | 186 | |
| 187 | + if ( this.safari ) { |
| 188 | + // Detect https://bugs.webkit.org/show_bug.cgi?id=25575 |
| 189 | + var match = /AppleWebKit\/([0-9]+)/.exec( navigator.userAgent ); |
| 190 | + if ( match ) { |
| 191 | + var major = parseInt( match[1] ); |
| 192 | + if ( major < 531 ) { |
| 193 | + this.safariControlsBug = true; |
| 194 | + } |
| 195 | + } |
| 196 | + } |
| 197 | + |
181 | 198 | // ActiveX plugins |
182 | 199 | // VLC |
183 | 200 | if ( this.testActiveX( 'VideoLAN.VLCPlugin.2' ) ) { |
— | — | @@ -195,24 +212,22 @@ |
196 | 213 | if ( typeof HTMLVideoElement == 'object' // Firefox, Safari |
197 | 214 | || typeof HTMLVideoElement == 'function' ) // Opera |
198 | 215 | { |
199 | | - //do another test for safari: |
200 | | - if( wgOggPlayer.safari ){ |
201 | | - try{ |
202 | | - var dummyvid = document.createElement("video"); |
203 | | - if (dummyvid.canPlayType && dummyvid.canPlayType("video/ogg;codecs=\"theora,vorbis\"") == "probably") |
| 216 | + // Safari does not support Theora by default, but later versions implement canPlayType() |
| 217 | + if ( this.safari ) { |
| 218 | + try { |
| 219 | + var video = document.createElement( 'video' ); |
| 220 | + if ( video.canPlayType |
| 221 | + && video.canPlayType( 'video/ogg;codecs="theora,vorbis"' ) == 'probably' ) |
204 | 222 | { |
205 | 223 | this.clientSupports['videoElement'] = true; |
206 | | - } else if(this.supportedMimeType('video/ogg')) { |
207 | | - /* older versions of safari do not support canPlayType, |
208 | | - but xiph qt registers mimetype via quicktime plugin */ |
| 224 | + } else if ( this.supportedMimeType( 'video/ogg' ) ) { |
| 225 | + // On older versions, XiphQT registers a plugin type and also handles <video> |
209 | 226 | this.clientSupports['videoElement'] = true; |
210 | 227 | } else { |
211 | | - /* could add some user nagging to install the xiph qt */ |
| 228 | + // TODO: prompt for XiphQT install |
212 | 229 | } |
213 | | - }catch(e){ |
214 | | - //could not use canPlayType |
215 | | - } |
216 | | - }else{ |
| 230 | + } catch ( e ) {} |
| 231 | + } else { |
217 | 232 | this.clientSupports['videoElement'] = true; |
218 | 233 | } |
219 | 234 | } |
— | — | @@ -270,7 +285,9 @@ |
271 | 286 | // Note: Totem and KMPlayer also use this pluginName, which is |
272 | 287 | // why we check for them first |
273 | 288 | player = 'quicktime-mozilla'; |
274 | | - } else if ( (pluginName.toLowerCase() == 'vlc multimedia plugin') || (pluginName.toLowerCase() == 'vlc multimedia plug-in') ) { |
| 289 | + } else if ( (pluginName.toLowerCase() == 'vlc multimedia plugin') |
| 290 | + || (pluginName.toLowerCase() == 'vlc multimedia plug-in') ) |
| 291 | + { |
275 | 292 | player = 'vlc-mozilla'; |
276 | 293 | } else if ( type == 'application/ogg' ) { |
277 | 294 | player = 'oggPlugin'; |
— | — | @@ -345,52 +362,7 @@ |
346 | 363 | } |
347 | 364 | return hasObj; |
348 | 365 | }, |
349 | | - 'webkitVersionIsAtLeast' : function ( minimumString ) { |
350 | | - var version = function() { |
351 | | - // grab (AppleWebKit/)(xxx.x.x) |
352 | | - var webKitFields = RegExp("( AppleWebKit/)([^ ]+)").exec(navigator.userAgent); |
353 | | - if (!webKitFields || webKitFields.length < 3) |
354 | | - return null; |
355 | | - var versionString = webKitFields[2]; |
356 | | - var isNightlyBuild = versionString.indexOf("+") != -1; |
357 | 366 | |
358 | | - // Remove '+' or any other stray characters |
359 | | - var invalidCharacter = RegExp("[^\\.0-9]").exec(versionString); |
360 | | - if (invalidCharacter) |
361 | | - versionString = versionString.slice(0, invalidCharacter.index); |
362 | | - |
363 | | - var version = versionString.split("."); |
364 | | - version.isNightlyBuild = isNightlyBuild; |
365 | | - return version; |
366 | | - } |
367 | | - var toIntOrZero = function (s) { |
368 | | - var toInt = parseInt(s); |
369 | | - return isNaN(toInt) ? 0 : toInt; |
370 | | - } |
371 | | - |
372 | | - if (minimumString === undefined) |
373 | | - minimumString = ""; |
374 | | - |
375 | | - var minimum = minimumString.split("."); |
376 | | - var version = version(); |
377 | | - |
378 | | - if (!version) |
379 | | - return false; |
380 | | - |
381 | | - if (version.isNightlyBuild) |
382 | | - return true; |
383 | | - |
384 | | - for (var i = 0; i < minimum.length; i++) { |
385 | | - var versionField = toIntOrZero(version[i]); |
386 | | - var minimumField = toIntOrZero(minimum[i]); |
387 | | - |
388 | | - if (versionField > minimumField) |
389 | | - return true; |
390 | | - if (versionField < minimumField) |
391 | | - return false; |
392 | | - } |
393 | | - return true; |
394 | | - }, |
395 | 367 | 'addOption' : function ( select, value, text, selected ) { |
396 | 368 | var option = document.createElement( 'option' ); |
397 | 369 | option.value = value; |
— | — | @@ -586,17 +558,18 @@ |
587 | 559 | |
588 | 560 | 'embedVideoElement': function ( elt, params ) { |
589 | 561 | var id = elt.id + "_obj"; |
590 | | - var mtag = (params.isVideo?'video':'audio'); |
| 562 | + var tagName = params.isVideo ? 'video' : 'audio'; |
591 | 563 | var html = |
592 | | - '<div><' + mtag + |
| 564 | + '<div><' + tagName + |
593 | 565 | ' id=' + this.hq( id ) + |
594 | 566 | ' width=' + this.hq( params.width ) + |
595 | 567 | ' height=' + this.hq( (params.height>0)?params.height:this.controlsHeightGuess ) + |
596 | 568 | ' src=' + this.hq( params.videoUrl ) + |
597 | 569 | ' autoplay'; |
598 | | - if (!this.safari || this.webkitVersionIsAtLeast('530.19.2')) |
| 570 | + if ( !this.safariControlsBug ) { |
599 | 571 | html += ' controls'; |
600 | | - html += ' ></' + mtag + '></div>'; |
| 572 | + } |
| 573 | + html += ' ></' + tagName + '></div>'; |
601 | 574 | elt.innerHTML = html; |
602 | 575 | }, |
603 | 576 | |
— | — | @@ -604,7 +577,7 @@ |
605 | 578 | var id = elt.id + "_obj"; |
606 | 579 | elt.innerHTML += |
607 | 580 | "<div><object id=" + this.hq( id ) + |
608 | | - " type='" + this.mimeTypes[player] + "'" + |
| 581 | + " type=" + this.hq( this.mimeTypes[player] ) + |
609 | 582 | " width=" + this.hq( params.width ) + |
610 | 583 | " height=" + this.hq( params.height + this.controlsHeightGuess ) + |
611 | 584 | " data=" + this.hq( params.videoUrl ) + "></object></div>"; |
— | — | @@ -614,7 +587,7 @@ |
615 | 588 | var id = elt.id + "_obj"; |
616 | 589 | elt.innerHTML += |
617 | 590 | "<div><object id=" + this.hq( id ) + |
618 | | - " type='" + this.mimeTypes['vlc-mozilla'] + "'" + |
| 591 | + " type=" + this.hq( this.mimeTypes['vlc-mozilla'] ) + |
619 | 592 | " width=" + this.hq( params.width ) + |
620 | 593 | " height=" + this.hq( params.height ) + |
621 | 594 | " data=" + this.hq( params.videoUrl ) + "></object></div>"; |