How to capture WMP events with script (and not HTML)?

Tech-Archive recommends: Fix windows errors by optimizing your registry



Hello:

How does one capture Windows Media Player events in JScript?

I have a .js library that creates a WMP ActiveXControl and then plays a
media file. I want to capture the "PlayStateChangeEvent".

PlayerObj.PlayStateChangeEvents = function ( ) { ... }

This code gives an error, stating that the property does not exist. I
have found in the SDK that you can use "<SCRIPT FOR..EVENT></SCRIPT>"
block in order to achieve this. But, I guess I am confused why you
would have to write-out HTML in order to get JScript functionality.
This is a .js library after all, so writing JScript in <SCRIPT> seems
remarkably contradictory to achieve an event handler.

Clearly this should be possible: With other ActiveX controls, you
simply specify a function to handle events. For example, with
Microsoft's own XMLHTTP embedded component you just do

WebStreamObj = new ActiveXObject( 'Microsoft.XMLHTTP' );
WebStreamObj.onreadystatechange = function ( NewReadyStateID ) { .. };

This event handler even receives a parameter.

So, clearly Microsoft has established a standard, and proven that it is
possible to define entirely scriptable event handlers for ActiveX
controls *without* requiring an HTML parser. Of course, even with
ActiveX aside, capturing events for ordinary HTML documents is
likewise:

window.onload = function ( ) { alert( 'loaded' };

But for some odd reason, WMP doesn't follow these conventions. You have
to resort to embedding a JScript function inside HTML and embedding all
of that as a string to be written out to a dummy-HTML document from
within JScript to accomplish what is normally one line of code with
JScript alone. (This presumes that the HTML document remains resident,
otherwise you've lost the event handler. This also introduces the issue
of not being able to dynamically reassign the event handler because it
is outputted as "hardcoded HTML," which does not seem particularly
programmatic. Instead you have to resort to changing the dispatch
function itself.)

The Microsoft MSDN site states "Unlike standard events that can be
bound using attributes or properties, in the case of custom objects
these are not available. Use the FOR attribute to specify which element
or object to handle, assigning it an identifier or the name of an
object, application, or control."

I find it unbelievable that Microsoft itself does not keep its own
standards straight. They design other well-known ActiveX controls (like
he one I showed above as well as others) that do expose specific
properties for reassignment with scriptable event handlers. So the MSDN
site, is not correct in asserting that script authors must use SCRIPT
FOR..EVENT tags.

--Randall

.



Relevant Pages

  • Re: .NET AddIn Question re:UserControl in Folder homepage
    ... I tried passing it via the jscript but it always comes through null. ... It's just the oAddInObject in the usercontrol Initialize method is ... This is a .NET 1.1 Shimmed Outlook Add-in written in C# ... I have a .NET winforms UserControl hosted inside a HTML page which is ...
    (microsoft.public.outlook.program_vba)
  • Re: newbie document.write question
    ... but once I figured out .insertAdjacentHTML was jscript ... > It is used to inserts the given HTML text into the element ... >>sets cell backgrounds by combobox values. ...
    (microsoft.public.scripting.vbscript)
  • Re: ActiveXObject, jscript: Publishing a table as static html
    ... ActiveXObject and Excel 2007 ... I would like to create a html file containing this ... The way to see the table in the .htm form through a menu system is by ... I need an jscript method. ...
    (microsoft.public.scripting.jscript)
  • Re: custom http request headers
    ... inside of a HTML page loaded in a browser and you want to add HTTP ... request headers for a link that a user clicks in the HTML page then I ... But a lot of people use JScript in Windows Script Host or ASP or even ... and there you can add request headers, the documentation is here: ...
    (microsoft.public.scripting.jscript)
  • What type of objects/controls?
    ... I need to create a class that will be instantiated in Delphi6 but also in ... JScript (to run JScript from Delphi application I'm using MS Script ActiveX ... Do I have to create an ActiveX or OLE Automation Objects that would be ...
    (alt.comp.lang.borland-delphi)