-->
Save your seat for Streaming Media NYC this May. Register Now!

The Windows Media ActiveX Control – Not Just for Internet Explorer Anymore

Detecting the Windows Media Player
In your pages, you can test for the presence of the Windows Media ActiveX control with the following JavaScript:

01 var player; 02 var plugin; 03 var hasActiveX=false; 04 try{ 05 if(window.ActiveXObject) 06 { 07 hasActiveX = true; 08 player = new ActiveXObject("WMPlayer.OCX.7"); 09 } 10 else if (window.GeckoActiveXObject) 11 { 12 hasActiveX = true; 13 player = new GeckoActiveXObject("WMPlayer.OCX.7"); 14 } 15 } catch(oError) { } 16 try{ 17 if(navigator.mimeTypes) 18 { 19 plugin = navigator.mimeTypes['application/x-mplayer2'].enabledPlugin; 20 } 21 }catch (oError) {} 22 var message = "Your browser "+ (hasActiveX ? "does" : " does not") +" support ActiveX. \n"; 23 message += "The WMP ActiveX control is"+ ( player ? "" : " not") +" installed. \n"; 24 message += "The WMP Plugin "+ (plugin ? "is" : "is not") +" installed. \n"; 25 alert(message); Try it by clicking here. If you have Javascript enabled, you'll see an alert box that tells you whether your browser supports ActiveX and whether it has the WMP 7/9 ActiveX control or the WMP 6.4 plugin installed.

The code between lines 4 and 15 try to detect browser support for ActiveX controls. The try/catch structure intercepts any errors generated within the block so that, in the event that ActiveX is not detected, the user doesn't get cryptic messages like "object has no properties." Lines 5 and 10 test for ActiveX support in the browser. Notice that line 10, the Mozilla test, is different from the line 5 test for IE. Some Web pages use the window.ActiveXObject test as shorthand to determine if a user is using Internet Explorer on Windows. Mozilla calls its ActiveX object GeckoActiveXObject so that sites that use this technique will not break.

If ActiveX is supported, lines 8 and 13 attempt to create an instance of the WindowsMedia 7 or 9 player. If these fail, the error is caught on line 15 and execution drops down to line 19 to test for the WM plugin.

Streaming Covers
Free
for qualified subscribers
Subscribe Now Current Issue Past Issues