Tuesday, February 9
 
Home
Global Site

Upcoming Shows

Blog

SM U.S. Magazine

SM Europe Magazine

Streaming Media TV

Newsletters

Industry News

Readers Choice

Podcasts

Research Reports

Web Events

SM White Papers

Industry White Papers

Video Tutorials

Conference Videos

Forums

Discussion Lists

Industry Directory

Industry Jobs

ACACIA Patent Info

Research Centers

What Is Streaming?

Glossary

Advertising Info

About Us

Other Related Sites






Print versionSend to a friend!

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


by Larry Bouthillier
March 17, 2004


advertisement
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.

next>>
View page: 1  2  3  4 
Comments about this story :
>> full text
>> This works well on all browsers in Windows... full text

Write a Comment on this Story