Windows Media Player Javascript Detect and Embed

Geoff Stearns over at wrote a great script to detect and embed Flash objects, called SWFObject embed. What I love about it is that it is really simple to use and bypasses the problems of the Eolas v Microsoft debarcle (Click to activate this control). He also produced a Quicktime detect and embed alongside the Flash SWFObject that is also very useful. I needed a similar script for Windows Media Players, so without being able to find a great example, I knocked this up, based on his code.

First we create the WMPObject:

Then deal with any parameters that are passed:

We then have a function to generate the core HTML and return a string of HTML code:

And deal with attributes:

Write the generated HTML out to the page:

And deal with plugin detection:

Then to use the WMPObject, you can use the following:

Download a fully functional demo of this code from

Ben Powell

Ben Powell was born in Wales and after living in several European countries is now resident in Germany. He is a frequent blogger, software developer and a social techie.

You may also like...

7 Responses

  1. Great,
    Could you please post the zip file?

  2. Ben says:

    I have created a zip file with the Javascript include file only. There is no demo, but at some point I’ll warp it all together.

    If you follow the instructions for the Quicktime example that Geoff Stearns has created and switch the references in your HTML code for the wmpObject instead, you shouldn’t go far wrong.

    The file can be found here:

    Geoff’s information on the Quicktime Object detect and embed is here:

  3. nopeahopea says:

    Excellent work.

    Unfortunately, a huge problem remains: when scaling embedded video, firefox (and other non-IE pc browsers) tend to not scale the video height when user has WMP 11 installed. This doesn’t have anything to do with the script though. The problem relies on the general plugin implementation.

    For example, let’s say you wanted to scale up a 320×240 video to 640×480 – the video width is expanded to 640px but the height remains at 240px.

    Have you guys come around this problem?

  4. Ben says:

    You could try adding the following parameter:

    A Google search turned this up, but I haven’t tried it out.

  5. levani says:

    Thanks for this effort.
    I hope you dont mind, I have created YUI component using your script,
    I have retained parameters management and browser Detection code.
    wiki has credit link to this page.
    I was not sure what license it was under, but I will put credints inside source code as well once I document it.

  6. Anonymous says:

    Hi Ben,
    Using your isWMPInstalled() when testing on my system it will return two instances of WMP, one for the full WMP and one for the Firefox WMP Plugin which I’ve also installed. You don’t know how to check for just the plugin do you? I’m wanting FF users to see wmp visualization as music plays but this will only work with wmp plugin installed.

  7. Ben says:

    Hi Anon. I’m afraid I haven’t looked at this project for about 3 years. How about using the jQuery Media Plugin:

Feel free to leave constructive comments that aren't spam!

%d bloggers like this: