integrating a "Windows Media Player" object and catching its DOM events

According to the Microsoft documentation, there are two dirty ways to catch such objects DOM events :

Here are two exemples using the "PlayStateChange" event :

<!-- integrate the WMP object -->
<object id="Player" type="application/x-ms-wmp" width="300" height="200">
    <param name="URL" value="c:\MediaFiles\Seattle.wmv"/>

<!-- the first one -->
<script for="Player" event="PlayStateChange(newState)">
    console.log("newState: " + newState);

<!-- the second one -->
function OnDSPlayStateChangeEvt(newState) {
    console.log("newState: " + newState);

The two script tag properties "for" and "event" don't appear in the HTML standards, nevertheless that way works fine with Internet Explorer 6, 7 and Firefox 2, but doesn't with Firefox 3 . The second one works on all those browsers, but a problem appears when several player instances are running. How to know which one has fired the event ?

An alternate way is using DOM level 2 events. However, the WMP plugin for Firefox doesn't fire its events in the DOM. Instead of it, the plugin probably look for matching script tags and eval the content it found.

Then, on Internet Explorer, and contrary to all other events in this browser, the ones from WMP objects are not prefixed by "on" (like "onMouseOut", "onClick" …). Since the javascript libraries like mootools or prototype follow that Microsoft "standard", their event listeners on DOM elements are useless.

So, the good syntax to make it work with IE is :

document.getElementById('Player').attachEvent("PlayStateChange",function(newState) {
    console.log("newState: " + newState);

blog comments powered by Disqus